diff --git a/crates/lib-dialects/src/lib.rs b/crates/lib-dialects/src/lib.rs index 29acbedf8..9f3dc609d 100644 --- a/crates/lib-dialects/src/lib.rs +++ b/crates/lib-dialects/src/lib.rs @@ -25,6 +25,8 @@ pub mod duckdb; pub mod hive; #[cfg(feature = "mysql")] pub mod mysql; +#[cfg(feature = "mysql")] +mod mysql_keywords; #[cfg(feature = "postgres")] pub mod postgres; #[cfg(feature = "postgres")] diff --git a/crates/lib-dialects/src/mysql.rs b/crates/lib-dialects/src/mysql.rs index ba916c83f..df3b3f935 100644 --- a/crates/lib-dialects/src/mysql.rs +++ b/crates/lib-dialects/src/mysql.rs @@ -1,10 +1,19 @@ +use super::ansi::{self}; +use crate::mysql_keywords::{MYSQL_RESERVED_KEYWORDS, MYSQL_UNRESERVED_KEYWORDS}; use sqruff_lib_core::dialects::base::Dialect; use sqruff_lib_core::dialects::init::DialectKind; use sqruff_lib_core::dialects::syntax::SyntaxKind; -use sqruff_lib_core::helpers::Config; -use sqruff_lib_core::parser::lexer::Matcher; - -use super::ansi; +use sqruff_lib_core::helpers::{Config, ToMatchable}; +use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; +use sqruff_lib_core::parser::grammar::base::{Anything, Ref}; +use sqruff_lib_core::parser::grammar::delimited::Delimited; +use sqruff_lib_core::parser::grammar::sequence::Bracketed; +use sqruff_lib_core::parser::matchable::MatchableTrait; +use sqruff_lib_core::parser::node_matcher::NodeMatcher; +use sqruff_lib_core::parser::parsers::{RegexParser, StringParser, TypedParser}; +use sqruff_lib_core::parser::segments::meta::MetaSegment; +use sqruff_lib_core::vec_of_erased; +use sqruff_lib_core::{parser::grammar::sequence::Sequence, parser::lexer::Matcher}; pub fn dialect() -> Dialect { raw_dialect().config(|dialect| dialect.expand()) @@ -20,5 +29,1721 @@ pub fn raw_dialect() -> Dialect { SyntaxKind::InlineComment, )]); + // # Set Keywords + // Do not clear inherited unreserved ansi keywords. Too many are needed to parse well. + // Just add MySQL unreserved keywords. + mysql.update_keywords_set_from_multiline_string( + "unreserved_keywords", + MYSQL_UNRESERVED_KEYWORDS, + ); + mysql.sets("reserved_keywords").clear(); + mysql.update_keywords_set_from_multiline_string("reserved_keywords", MYSQL_RESERVED_KEYWORDS); + + // Set the datetime units + mysql.sets_mut("datetime_units").clear(); + mysql.sets_mut("datetime_units").extend(vec![ + // https://github.com/mysql/mysql-server/blob/1bfe02bdad6604d54913c62614bde57a055c8332/sql/sql_yacc.yy#L12321-L12345 + // interval: + "DAY_HOUR", + "DAY_MICROSECOND", + "DAY_MINUTE", + "DAY_SECOND", + "HOUR_MICROSECOND", + "HOUR_MINUTE", + "HOUR_SECOND", + "MINUTE_MICROSECOND", + "MINUTE_SECOND", + "SECOND_MICROSECOND", + "YEAR_MONTH", + // interval_time_stamp + "DAY", + "WEEK", + "HOUR", + "MINUTE", + "MONTH", + "QUARTER", + "SECOND", + "MICROSECOND", + "YEAR", + ]); + + mysql.sets_mut("date_part_function_name").clear(); + mysql.sets_mut("date_part_function_name").extend(vec![ + "EXTRACT", + "TIMESTAMPADD", + "TIMESTAMPDIFF", + ]); + + mysql.add([( + // MySQL allows the usage of a double quoted identifier for an alias. + "DoubleQuotedIdentifierSegment".into(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::Identifier) + .to_matchable() + .into(), + )]); + + mysql.add([ + ( + // A session variable name, e.g. @variable_name + "SessionVariableNameSegment".into(), + RegexParser::new(r"[@][a-zA-Z0-9_$]*", SyntaxKind::Variable) + .to_matchable() + .into(), + ), + ( + // A local variable name, e.g. variable_name or `variable_name` + "LocalVariableNameSegment".into(), + RegexParser::new(r"`?[a-zA-Z0-9_$]*`?", SyntaxKind::Variable) + .to_matchable() + .into(), + ), + ( + // A walrus operator, e.g. := + "WalrusOperatorSegment".into(), + StringParser::new(":=", SyntaxKind::AssignmentOperator) + .to_matchable() + .into(), + ), + ( + // A double quoted literal segment, e.g. "literal" + "DoubleQuotedLiteralSegment".into(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::Literal) + .to_matchable() + .into(), + ), + ( + // A system variable segment, e.g. @@variable_name, @@session.variable_name, @@global.variable_name + "SystemVariableSegment".into(), + RegexParser::new( + r"@@((session|global)\.)?[A-Za-z0-9_]+", + SyntaxKind::Variable, + ) + .to_matchable() + .into(), + ), + ( + // Boolean dynamic system variables grammar + // Boolean dynamic system variables can be set to ON/OFF, TRUE/FALSE, or 0/1 + // https://dev.mysql.com/doc/refman/8.0/en/dynamic-system-variables.html + "BooleanDynamicSystemVariablesGrammar".into(), + one_of(vec_of_erased![ + one_of(vec_of_erased![Ref::keyword("ON"), Ref::keyword("OFF"),]), + one_of(vec_of_erased![Ref::keyword("TRUE"), Ref::keyword("FALSE"),]), + ]) + .to_matchable() + .into(), + ), + ]); + + mysql.add([ + ( + // A reference to an object with an `AS` clause. + // The optional AS keyword allows both implicit and explicit aliasing. + "AliasExpressionSegment".into(), + Sequence::new(vec_of_erased![ + MetaSegment::indent(), + Ref::keyword("AS").optional(), + one_of(vec_of_erased![ + Ref::new("SingleIdentifierGrammar"), + Ref::new("SingleQuotedIdentifierSegment"), + Ref::new("DoubleQuotedIdentifierSegment"), + ]), + MetaSegment::dedent(), + ]) + .to_matchable() + .into(), + ), + ( + // A column definition, e.g. for CREATE TABLE or ALTER TABLE. + "ColumnDefinitionSegment".into(), + Sequence::new(vec_of_erased![ + Ref::new("SingleIdentifierGrammar"), // Column name + one_of(vec_of_erased![ + // DATETIME and TIMESTAMP take special logic + Ref::new("DatatypeSegment").exclude(one_of(vec_of_erased![ + Ref::keyword("DATETIME"), + Ref::keyword("TIMESTAMP"), + ])), + Sequence::new(vec_of_erased![ + one_of(vec_of_erased![ + Ref::keyword("DATETIME"), + Ref::keyword("TIMESTAMP"), + ]), + Bracketed::new(vec_of_erased![Ref::new("NumericLiteralSegment"),]) + .config(|bracketed| bracketed.optional()), // Precision + AnyNumberOf::new(vec_of_erased![ + // Allow NULL/NOT NULL, DEFAULT, and ON UPDATE in any order + Sequence::new(vec_of_erased![ + Sequence::new(vec_of_erased![Ref::keyword("NOT"),]) + .config(|sequence| sequence.optional()), + Ref::keyword("NULL"), + ]) + .config(|sequence| sequence.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("DEFAULT"), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + one_of(vec_of_erased![ + Ref::keyword("CURRENT_TIMESTAMP"), + Ref::keyword("NOW"), + ]), + Bracketed::new(vec_of_erased![ + Ref::new("NumericLiteralSegment").optional() + ]) + .config(|bracketed| bracketed.optional()), + ]), + Ref::new("NumericLiteralSegment"), + Ref::new("QuotedLiteralSegment"), + Ref::keyword("NULL"), + ]), + ]) + .config(|sequence| sequence.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("ON"), + Ref::keyword("UPDATE"), + one_of(vec_of_erased![ + Ref::keyword("CURRENT_TIMESTAMP"), + Ref::keyword("NOW"), + ]), + Bracketed::new(vec_of_erased![ + Ref::new("NumericLiteralSegment").optional() + ]) + .config(|bracketed| bracketed.optional()), + ]) + .config(|sequence| sequence.optional()), + ]) + .config(|any_number| any_number.optional()), + ]), + ]), + Bracketed::new(vec_of_erased![Anything::new(),]) + .config(|bracketed| bracketed.optional()), // For types like VARCHAR(100) + AnyNumberOf::new(vec_of_erased![ + Ref::new("ColumnConstraintSegment").optional(), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // This is a `CREATE USER` statement. + // https://dev.mysql.com/doc/refman/8.0/en/create-user.html + "CreateUserStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("CREATE"), + Ref::keyword("USER"), + Ref::new("IfNotExistsGrammar").optional(), + Delimited::new(vec_of_erased![Sequence::new(vec_of_erased![ + Ref::new("RoleReferenceSegment"), + Sequence::new(vec_of_erased![ + Delimited::new(vec_of_erased![Sequence::new(vec_of_erased![ + Ref::keyword("IDENTIFIED"), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("BY"), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("RANDOM"), + Ref::keyword("PASSWORD"), + ]), + Ref::new("QuotedLiteralSegment"), + ]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("WITH"), + Ref::new("ObjectReferenceSegment"), + Sequence::new(vec_of_erased![one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("BY"), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("RANDOM"), + Ref::keyword("PASSWORD"), + ]), + Ref::new("QuotedLiteralSegment"), + ]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("AS"), + Ref::new("QuotedLiteralSegment"), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("INITIAL"), + Ref::keyword("AUTHENTICATION"), + Ref::keyword("IDENTIFIED"), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("BY"), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("RANDOM"), + Ref::keyword("PASSWORD"), + ]), + Ref::new("QuotedLiteralSegment"), + ]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("WITH"), + Ref::new("ObjectReferenceSegment"), + Ref::keyword("AS"), + Ref::new("QuotedLiteralSegment"), + ]), + ]), + ]), + ]),]) + .config(|sequence| sequence.optional()), + ]), + ]), + ]),]) + .config(|delimited| delimited.delimiter(Ref::keyword("AND"))), + ]) + .config(|sequence| sequence.optional()), + ]),]), + Sequence::new(vec_of_erased![ + Ref::keyword("DEFAULT"), + Ref::keyword("ROLE"), + Delimited::new(vec_of_erased![Ref::new("RoleReferenceSegment")]), + ]) + .config(|sequence| sequence.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("REQUIRE"), + one_of(vec_of_erased![ + Ref::keyword("NONE"), + Delimited::new(vec_of_erased![one_of(vec_of_erased![ + Ref::keyword("SSL"), + Ref::keyword("X509"), + Sequence::new(vec_of_erased![ + Ref::keyword("CIPHER"), + Ref::new("QuotedLiteralSegment"), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("ISSUER"), + Ref::new("QuotedLiteralSegment"), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("SUBJECT"), + Ref::new("QuotedLiteralSegment"), + ]), + ]),]) + .config(|delimited| delimited.delimiter(Ref::keyword("AND"))), + ]), + ]) + .config(|sequence| sequence.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("WITH"), + AnyNumberOf::new(vec_of_erased![Sequence::new(vec_of_erased![ + one_of(vec_of_erased![ + Ref::keyword("MAX_QUERIES_PER_HOUR"), + Ref::keyword("MAX_UPDATES_PER_HOUR"), + Ref::keyword("MAX_CONNECTIONS_PER_HOUR"), + Ref::keyword("MAX_USER_CONNECTIONS"), + ]), + Ref::new("NumericLiteralSegment"), + ]),]), + ]) + .config(|sequence| sequence.optional()), + Sequence::new(vec_of_erased![AnyNumberOf::new(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("PASSWORD"), + Ref::keyword("EXPIRE"), + Sequence::new(vec_of_erased![one_of(vec_of_erased![ + Ref::keyword("DEFAULT"), + Ref::keyword("NEVER"), + Sequence::new(vec_of_erased![ + Ref::keyword("INTERVAL"), + Ref::new("NumericLiteralSegment"), + Ref::keyword("DAY"), + ]), + ]),]) + .config(|sequence| sequence.optional()), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("PASSWORD"), + Ref::keyword("HISTORY"), + one_of(vec_of_erased![ + Ref::keyword("DEFAULT"), + Ref::new("NumericLiteralSegment"), + ]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("PASSWORD"), + Ref::keyword("REUSE"), + Ref::keyword("INTERVAL"), + one_of(vec_of_erased![ + Ref::keyword("DEFAULT"), + Sequence::new(vec_of_erased![ + Ref::new("NumericLiteralSegment"), + Ref::keyword("DAY"), + ]), + ]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("PASSWORD"), + Ref::keyword("REQUIRE"), + Ref::keyword("CURRENT"), + Sequence::new(vec_of_erased![one_of(vec_of_erased![ + Ref::keyword("DEFAULT"), + Ref::keyword("OPTIONAL"), + ]),]) + .config(|sequence| sequence.optional()), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("FAILED_LOGIN_ATTEMPTS"), + Ref::new("NumericLiteralSegment"), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("PASSWORD_LOCK_TIME"), + one_of(vec_of_erased![ + Ref::new("NumericLiteralSegment"), + Ref::keyword("UNBOUNDED"), + ]), + ]), + ]),]) + .config(|sequence| sequence.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("ACCOUNT"), + one_of(vec_of_erased![Ref::keyword("UNLOCK"), Ref::keyword("LOCK")]), + ]) + .config(|sequence| sequence.optional()), + Sequence::new(vec_of_erased![ + one_of(vec_of_erased![ + Ref::keyword("COMMENT"), + Ref::keyword("ATTRIBUTE") + ]), + Ref::new("QuotedLiteralSegment"), + ]) + .config(|sequence| sequence.optional()), + ]) + .to_matchable() + .into(), + ), + ( + // This is a CLOSE or Open statement. + // https://dev.mysql.com/doc/refman/8.0/en/close.html + // https://dev.mysql.com/doc/refman/8.0/en/open.html + "CursorOpenCloseSegment".into(), + Sequence::new(vec_of_erased![ + one_of(vec_of_erased![Ref::keyword("CLOSE"), Ref::keyword("OPEN"),]), + one_of(vec_of_erased![ + Ref::new("SingleIdentifierGrammar"), + Ref::new("QuotedIdentifierSegment"), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // A `ITERATE` statement. + // https://dev.mysql.com/doc/refman/8.0/en/iterate.html + "IterateStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("ITERATE"), + Ref::new("SingleIdentifierGrammar"), + ]) + .to_matchable() + .into(), + ), + ( + // This is the body of a `EXECUTE` statement. + // https://dev.mysql.com/doc/refman/8.0/en/execute.html + "ExecuteSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("EXECUTE"), + Ref::new("NakedIdentifierSegment"), + Sequence::new(vec_of_erased![ + Ref::keyword("USING"), + Delimited::new(vec_of_erased![Ref::new("SessionVariableNameSegment")]), + ]) + .config(|delimited| delimited.optional()), + ]) + .to_matchable() + .into(), + ), + ( + // A `REPEAT-UNTIL` statement. + // https://dev.mysql.com/doc/refman/8.0/en/repeat.html + "RepeatStatementSegment".into(), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::new("SingleIdentifierGrammar"), + Ref::new("ColonSegment"), + ]) + .config(|sequence| sequence.optional()), + Ref::keyword("REPEAT"), + AnyNumberOf::new(vec_of_erased![Ref::new("StatementSegment")]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("UNTIL"), + Ref::new("ExpressionSegment"), + Sequence::new(vec_of_erased![ + Ref::keyword("END"), + Ref::keyword("REPEAT"), + Ref::new("SingleIdentifierGrammar").optional(), + ]), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // This is the body of a `DEALLOCATE/DROP` statement. + // https://dev.mysql.com/doc/refman/8.0/en/deallocate-prepare.html + "DeallocateSegment".into(), + Sequence::new(vec_of_erased![ + Sequence::new(vec_of_erased![ + one_of(vec_of_erased![ + Ref::keyword("DEALLOCATE"), + Ref::keyword("DROP"), + ]), + Ref::keyword("PREPARE"), + ]), + Ref::new("NakedIdentifierSegment"), + ]) + .to_matchable() + .into(), + ), + ( + // This is the body of a `RESIGNAL` statement. + // https://dev.mysql.com/doc/refman/8.0/en/resignal.html + "ResignalSegment".into(), + Sequence::new(vec_of_erased![ + one_of(vec_of_erased![ + Ref::keyword("SIGNAL"), + Ref::keyword("RESIGNAL"), + ]), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("SQLSTATE"), + Ref::keyword("VALUE").optional(), + Ref::new("QuotedLiteralSegment"), + ]), + Ref::new("NakedIdentifierSegment"), + ]) + .config(|one_of| one_of.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("SET"), + Delimited::new(vec_of_erased![Sequence::new(vec_of_erased![ + one_of(vec_of_erased![ + Ref::keyword("CLASS_ORIGIN"), + Ref::keyword("SUBCLASS_ORIGIN"), + Ref::keyword("RETURNED_SQLSTATE"), + Ref::keyword("MESSAGE_TEXT"), + Ref::keyword("MYSQL_ERRNO"), + Ref::keyword("CONSTRAINT_CATALOG"), + Ref::keyword("CONSTRAINT_SCHEMA"), + Ref::keyword("CONSTRAINT_NAME"), + Ref::keyword("CATALOG_NAME"), + Ref::keyword("SCHEMA_NAME"), + Ref::keyword("TABLE_NAME"), + Ref::keyword("COLUMN_NAME"), + Ref::keyword("CURSOR_NAME"), + ]), + Ref::new("EqualsSegment"), + one_of(vec_of_erased![ + Ref::new("SessionVariableNameSegment"), + Ref::new("LocalVariableNameSegment"), + Ref::new("QuotedLiteralSegment"), + ]), + ]),]), + ]) + .config(|sequence| sequence.optional()), + ]) + .to_matchable() + .into(), + ), + ( + // This is a FETCH statement. + // https://dev.mysql.com/doc/refman/8.0/en/fetch.html + "CursorFetchSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("FETCH"), + Sequence::new(vec_of_erased![ + Ref::keyword("NEXT").optional(), + Ref::keyword("FROM"), + ]) + .config(|sequence| sequence.optional()), + Ref::new("NakedIdentifierSegment"), + Ref::keyword("INTO"), + Delimited::new(vec_of_erased![ + Ref::new("SessionVariableNameSegment"), + Ref::new("LocalVariableNameSegment"), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // This is a `DROP INDEX` statement. + // https://dev.mysql.com/doc/refman/8.0/en/drop-index.html + "DropIndexStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("DROP"), + Ref::keyword("INDEX"), + Ref::new("IndexReferenceSegment"), + Ref::keyword("ON"), + Ref::new("TableReferenceSegment"), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("ALGORITHM"), + Ref::new("EqualsSegment").optional(), + one_of(vec_of_erased![ + Ref::keyword("DEFAULT"), + Ref::keyword("INPLACE"), + Ref::keyword("COPY"), + ]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("LOCK"), + Ref::new("EqualsSegment").optional(), + one_of(vec_of_erased![ + Ref::keyword("DEFAULT"), + Ref::keyword("NONE"), + Ref::keyword("SHARED"), + Ref::keyword("EXCLUSIVE"), + ]), + ]), + ]) + .config(|delimited| delimited.optional()), + ]) + .to_matchable() + .into(), + ), + ( + // A `DROP` statement that addresses stored procedures and functions.. + // https://dev.mysql.com/doc/refman/8.0/en/drop-procedure.html + "DropProcedureStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("DROP"), + one_of(vec_of_erased![ + Ref::keyword("PROCEDURE"), + Ref::keyword("FUNCTION"), + ]), + Ref::new("IfExistsGrammar").optional(), + Ref::new("ObjectReferenceSegment"), + ]) + .to_matchable() + .into(), + ), + ( + // A `DROP` statement that addresses loadable functions. + // https://dev.mysql.com/doc/refman/8.0/en/drop-function-loadable.html + "DropFunctionStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("DROP"), + Ref::keyword("FUNCTION"), + Ref::new("IfExistsGrammar").optional(), + Ref::new("FunctionNameSegment"), + ]) + .to_matchable() + .into(), + ), + ( + // A `RENAME TABLE` statement. + // https://dev.mysql.com/doc/refman/8.0/en/rename-table.html + "RenameTableStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("RENAME"), + Ref::keyword("TABLE"), + Delimited::new(vec_of_erased![Sequence::new(vec_of_erased![ + Ref::new("TableReferenceSegment"), + Ref::keyword("TO"), + Ref::new("TableReferenceSegment"), + ]),]), + ]) + .to_matchable() + .into(), + ), + ( + // A `RESET MASTER` statement. + // https://dev.mysql.com/doc/refman/8.0/en/reset-master.html + "ResetMasterStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("RESET"), + Ref::keyword("MASTER"), + Sequence::new(vec_of_erased![ + Ref::keyword("TO"), + Ref::new("NumericLiteralSegment"), + ]) + .config(|sequence| sequence.optional()), + ]) + .to_matchable() + .into(), + ), + ( + // A `PURGE BINARY LOGS` statement. + // https://dev.mysql.com/doc/refman/8.0/en/purge-binary-logs.html + "PurgeBinaryLogsStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("PURGE"), + one_of(vec_of_erased![ + Ref::keyword("BINARY"), + Ref::keyword("MASTER"), + ]), + Ref::keyword("LOGS"), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("TO"), + Ref::new("QuotedLiteralSegment"), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("BEFORE"), + Ref::new("ExpressionSegment"), + ]), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // A `HELP` statement. + // https://dev.mysql.com/doc/refman/8.0/en/help.html + "HelpStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("HELP"), + Ref::new("QuotedLiteralSegment"), + ]) + .to_matchable() + .into(), + ), + ( + // A `CHECK TABLE` statement. + // https://dev.mysql.com/doc/refman/8.0/en/check-table.html + "CheckTableStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("CHECK"), + Ref::keyword("TABLE"), + Delimited::new(vec_of_erased![Ref::new("TableReferenceSegment"),]), + AnyNumberOf::new(vec_of_erased![ + Sequence::new(vec_of_erased![Ref::keyword("FOR"), Ref::keyword("UPGRADE"),]), + Ref::keyword("QUICK"), + Ref::keyword("FAST"), + Ref::keyword("MEDIUM"), + Ref::keyword("EXTENDED"), + Ref::keyword("CHANGED"), + ]) + .config(|any_number| any_number.min_times(1)), + ]) + .to_matchable() + .into(), + ), + ( + // A `CHECKSUM TABLE` statement. + // https://dev.mysql.com/doc/refman/8.0/en/checksum-table.html + "ChecksumTableStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("CHECKSUM"), + Ref::keyword("TABLE"), + Delimited::new(vec_of_erased![Ref::new("TableReferenceSegment"),]), + one_of(vec_of_erased![ + Ref::keyword("QUICK"), + Ref::keyword("EXTENDED"), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // An `ANALYZE TABLE` statement. + // https://dev.mysql.com/doc/refman/8.0/en/analyze-table.html + "AnalyzeTableStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("ANALYZE"), + one_of(vec_of_erased![ + Ref::keyword("NO_WRITE_TO_BINLOG"), + Ref::keyword("LOCAL"), + ]) + .config(|one| one.optional()), + Ref::keyword("TABLE"), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![Delimited::new(vec_of_erased![Ref::new( + "TableReferenceSegment" + ),]),]), + Sequence::new(vec_of_erased![ + Ref::new("TableReferenceSegment"), + Ref::keyword("UPDATE"), + Ref::keyword("HISTOGRAM"), + Ref::keyword("ON"), + Delimited::new(vec_of_erased![Ref::new("ColumnReferenceSegment"),]), + Sequence::new(vec_of_erased![ + Ref::keyword("WITH"), + Ref::new("NumericLiteralSegment"), + Ref::keyword("BUCKETS"), + ]) + .config(|seq| seq.optional()), + ]), + Sequence::new(vec_of_erased![ + Ref::new("TableReferenceSegment"), + Ref::keyword("DROP"), + Ref::keyword("HISTOGRAM"), + Ref::keyword("ON"), + Delimited::new(vec_of_erased![Ref::new("ColumnReferenceSegment"),]), + ]), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // A `REPAIR TABLE` statement. + // https://dev.mysql.com/doc/refman/8.0/en/repair-table.html + "RepairTableStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("REPAIR"), + one_of(vec_of_erased![ + Ref::keyword("NO_WRITE_TO_BINLOG"), + Ref::keyword("LOCAL"), + ]) + .config(|one| one.optional()), + Ref::keyword("TABLE"), + Delimited::new(vec_of_erased![Ref::new("TableReferenceSegment"),]), + AnyNumberOf::new(vec_of_erased![ + Ref::keyword("QUICK"), + Ref::keyword("EXTENDED"), + Ref::keyword("USE_FRM"), + ]) + ]) + .to_matchable() + .into(), + ), + ( + // An `OPTIMIZE TABLE` statement. + // https://dev.mysql.com/doc/refman/8.0/en/optimize-table.html + "OptimizeTableStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("OPTIMIZE"), + one_of(vec_of_erased![ + Ref::keyword("NO_WRITE_TO_BINLOG"), + Ref::keyword("LOCAL"), + ]) + .config(|one| one.optional()), + Ref::keyword("TABLE"), + Delimited::new(vec_of_erased![Ref::new("TableReferenceSegment"),]), + ]) + .to_matchable() + .into(), + ), + ( + // An `UPDATE` statement. + // https://dev.mysql.com/doc/refman/8.0/en/update.html + "UpdateStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("UPDATE"), + Ref::keyword("LOW_PRIORITY").optional(), + Ref::keyword("IGNORE").optional(), + MetaSegment::indent(), + Delimited::new(vec_of_erased![ + Ref::new("TableReferenceSegment"), + Ref::new("FromExpressionSegment"), + ]), + MetaSegment::dedent(), + Ref::new("SetClauseListSegment"), + Ref::new("WhereClauseSegment").optional(), + Ref::new("OrderByClauseSegment").optional(), + Ref::new("LimitClauseSegment").optional(), + ]) + .to_matchable() + .into(), + ), + ( + // A `DELIMITER` statement. + "DelimiterStatement".into(), + Sequence::new(vec_of_erased![Ref::keyword("DELIMITER"),]) + .to_matchable() + .into(), + ), + ( + // A `DECLARE` statement. + // https://dev.mysql.com/doc/refman/8.0/en/declare-local-variable.html + // https://dev.mysql.com/doc/refman/8.0/en/declare-handler.html + // https://dev.mysql.com/doc/refman/8.0/en/declare-condition.html + // https://dev.mysql.com/doc/refman/8.0/en/declare-cursor.html + "DeclareStatement".into(), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("DECLARE"), + Ref::new("NakedIdentifierSegment"), + Ref::keyword("CURSOR"), + Ref::keyword("FOR"), + Ref::new("StatementSegment"), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("DECLARE"), + one_of(vec_of_erased![ + Ref::keyword("CONTINUE"), + Ref::keyword("EXIT"), + Ref::keyword("UNDO"), + ]), + Ref::keyword("HANDLER"), + Ref::keyword("FOR"), + one_of(vec_of_erased![ + Ref::keyword("SQLEXCEPTION"), + Ref::keyword("SQLWARNING"), + Sequence::new(vec_of_erased![Ref::keyword("NOT"), Ref::keyword("FOUND"),]), + Sequence::new(vec_of_erased![ + Ref::keyword("SQLSTATE"), + Ref::keyword("VALUE").optional(), + Ref::new("QuotedLiteralSegment"), + ]), + one_of(vec_of_erased![ + Ref::new("QuotedLiteralSegment"), + Ref::new("NumericLiteralSegment"), + Ref::new("NakedIdentifierSegment"), + ]), + ]), + Sequence::new(vec_of_erased![Ref::new("StatementSegment")]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("DECLARE"), + Ref::new("NakedIdentifierSegment"), + Ref::keyword("CONDITION"), + Ref::keyword("FOR"), + one_of(vec_of_erased![ + Ref::new("QuotedLiteralSegment"), + Ref::new("NumericLiteralSegment"), + ]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("DECLARE"), + Ref::new("LocalVariableNameSegment"), + Ref::new("DatatypeSegment"), + Sequence::new(vec_of_erased![ + Ref::keyword("DEFAULT"), + one_of(vec_of_erased![ + Ref::new("QuotedLiteralSegment"), + Ref::new("NumericLiteralSegment"), + Ref::new("FunctionSegment"), + ]), + ]) + .config(|seq| seq.optional()), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // A `CREATE PROCEDURE` statement. + // https://dev.mysql.com/doc/refman/8.0/en/create-procedure.html + "CreateProcedureStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("CREATE"), + Ref::new("DefinerSegment").optional(), + Ref::keyword("PROCEDURE"), + Ref::new("FunctionNameSegment"), + Ref::new("ProcedureParameterListGrammar").optional(), + Ref::new("CommentClauseSegment").optional(), + Ref::new("CharacteristicStatement").optional(), + Ref::new("FunctionDefinitionGrammar"), + ]) + .to_matchable() + .into(), + ), + ( + // A `SET TRANSACTION` statement. + // https://dev.mysql.com/doc/refman/8.0/en/set-transaction.html + "SetTransactionStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("SET"), + one_of(vec_of_erased![ + Ref::keyword("GLOBAL"), + Ref::keyword("SESSION"), + ]) + .config(|this| this.optional()), + Ref::keyword("TRANSACTION"), + Delimited::new(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("ISOLATION"), + Ref::keyword("LEVEL"), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("READ"), + one_of(vec_of_erased![ + Ref::keyword("COMMITTED"), + Ref::keyword("UNCOMMITTED"), + ]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("REPEATABLE"), + Ref::keyword("READ"), + ]), + Ref::keyword("SERIALIZABLE"), + ]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("READ"), + one_of(vec_of_erased![Ref::keyword("WRITE"), Ref::keyword("ONLY"),]), + ]), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // A `SET` statement. + // https://dev.mysql.com/doc/refman/8.0/en/set-variable.html + "SetAssignmentStatementSegment".into(), + NodeMatcher::new( + SyntaxKind::SetStatement, + Sequence::new(vec_of_erased![ + Ref::keyword("SET"), + Delimited::new(vec_of_erased![Sequence::new(vec_of_erased![ + Sequence::new(vec_of_erased![ + one_of(vec_of_erased![Ref::keyword("NEW"), Ref::keyword("OLD"),]), + Ref::new("DotSegment"), + ]) + .config(|this| this.optional()), + one_of(vec_of_erased![ + Ref::new("SessionVariableNameSegment"), + Ref::new("LocalVariableNameSegment"), + ]), + one_of(vec_of_erased![ + Ref::new("EqualsSegment"), + Ref::new("WalrusOperatorSegment"), + ]), + AnyNumberOf::new(vec_of_erased![ + Ref::new("QuotedLiteralSegment"), + Ref::new("DoubleQuotedLiteralSegment"), + Ref::new("SessionVariableNameSegment"), + Ref::new("SystemVariableSegment"), + // Match boolean keywords before local variables. + Ref::new("BooleanDynamicSystemVariablesGrammar"), + Ref::new("LocalVariableNameSegment"), + Ref::new("FunctionSegment"), + Ref::new("ArithmeticBinaryOperatorGrammar"), + Ref::new("ExpressionSegment"), + ]), + ]),]), + ]) + .to_matchable(), + ) + .to_matchable() + .into(), + ), + ( + // IF-THEN-ELSE-ELSEIF-END IF statement. + // https://dev.mysql.com/doc/refman/8.0/en/if.html + "IfExpressionStatement".into(), + AnyNumberOf::new(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("IF"), + Ref::new("ExpressionSegment"), + Ref::keyword("THEN"), + Ref::new("StatementSegment"), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("ELSEIF"), + Ref::new("ExpressionSegment"), + Ref::keyword("THEN"), + Ref::new("StatementSegment"), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("ELSE"), + Ref::new("StatementSegment"), + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![Ref::keyword("END"), Ref::keyword("IF"),]), + ]) + .to_matchable() + .into(), + ), + ( + // WHILE-DO-END WHILE statement. + // https://dev.mysql.com/doc/refman/8.0/en/while.html + "WhileStatementSegment".into(), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::new("SingleIdentifierGrammar"), + Ref::new("ColonSegment"), + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("WHILE"), + Ref::new("ExpressionSegment"), + Ref::keyword("DO"), + AnyNumberOf::new(vec_of_erased![Ref::new("StatementSegment"),]), + ]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("END"), + Ref::keyword("WHILE"), + Ref::new("SingleIdentifierGrammar").optional(), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // LOOP statement. + // https://dev.mysql.com/doc/refman/8.0/en/loop.html + "LoopStatementSegment".into(), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::new("SingleIdentifierGrammar"), + Ref::new("ColonSegment"), + ]) + .config(|this| this.optional()), + Ref::keyword("LOOP"), + AnyNumberOf::new(vec_of_erased![Ref::new("StatementSegment"),]), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("END"), + Ref::keyword("LOOP"), + Ref::new("SingleIdentifierGrammar").optional(), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // CALL statement used to execute a stored procedure. + // https://dev.mysql.com/doc/refman/8.0/en/call.html + "CallStoredProcedureSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("CALL"), + Ref::new("FunctionSegment"), + ]) + .to_matchable() + .into(), + ), + ( + // PREPARE statement. + // https://dev.mysql.com/doc/refman/8.0/en/prepare.html + "PrepareSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("PREPARE"), + Ref::new("NakedIdentifierSegment"), + Ref::keyword("FROM"), + one_of(vec_of_erased![ + Ref::new("QuotedLiteralSegment"), + Ref::new("SessionVariableNameSegment"), + Ref::new("LocalVariableNameSegment"), + ]), + ]) + .to_matchable() + .into(), + ), + ( + // GET DIAGNOSTICS statement. + // https://dev.mysql.com/doc/refman/8.0/en/get-diagnostics.html + "GetDiagnosticsSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("GET"), + Sequence::new(vec_of_erased![ + Ref::keyword("CURRENT"), + Ref::keyword("STACKED"), + ]) + .config(|this| this.optional()), + Ref::keyword("DIAGNOSTICS"), + Delimited::new(vec_of_erased![Sequence::new(vec_of_erased![ + one_of(vec_of_erased![ + Ref::new("SessionVariableNameSegment"), + Ref::new("LocalVariableNameSegment"), + ]), + Ref::new("EqualsSegment"), + one_of(vec_of_erased![ + Ref::keyword("NUMBER"), + Ref::keyword("ROW_COUNT"), + ]), + ])]) + .config(|this| this.optional()), + Ref::keyword("CONDITION"), + one_of(vec_of_erased![ + Ref::new("SessionVariableNameSegment"), + Ref::new("LocalVariableNameSegment"), + Ref::new("NumericLiteralSegment"), + ]), + Delimited::new(vec_of_erased![Sequence::new(vec_of_erased![ + one_of(vec_of_erased![ + Ref::new("SessionVariableNameSegment"), + Ref::new("LocalVariableNameSegment"), + ]), + Ref::new("EqualsSegment"), + one_of(vec_of_erased![ + Ref::keyword("CLASS_ORIGIN"), + Ref::keyword("SUBCLASS_ORIGIN"), + Ref::keyword("RETURNED_SQLSTATE"), + Ref::keyword("MESSAGE_TEXT"), + Ref::keyword("MYSQL_ERRNO"), + Ref::keyword("CONSTRAINT_CATALOG"), + Ref::keyword("CONSTRAINT_SCHEMA"), + Ref::keyword("CONSTRAINT_NAME"), + Ref::keyword("CATALOG_NAME"), + Ref::keyword("SCHEMA_NAME"), + Ref::keyword("TABLE_NAME"), + Ref::keyword("COLUMN_NAME"), + Ref::keyword("CURSOR_NAME"), + ]), + ])]) + .config(|this| this.optional()), + ]) + .to_matchable() + .into(), + ), + ( + // An `ALTER VIEW .. AS ..` statement. + // As specified in https://dev.mysql.com/doc/refman/8.0/en/alter-view.html + "AlterViewStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("ALTER"), + Sequence::new(vec_of_erased![ + Ref::keyword("ALGORITHM"), + Ref::new("EqualsSegment"), + one_of(vec_of_erased![ + Ref::keyword("UNDEFINED"), + Ref::keyword("MERGE"), + Ref::keyword("TEMPTABLE"), + ]), + ]) + .config(|this| this.optional()), + Ref::new("DefinerSegment").optional(), + Sequence::new(vec_of_erased![ + Ref::keyword("SQL"), + Ref::keyword("SECURITY"), + one_of(vec_of_erased![ + Ref::keyword("DEFINER"), + Ref::keyword("INVOKER"), + ]), + ]) + .config(|this| this.optional()), + Ref::keyword("VIEW"), + Ref::new("TableReferenceSegment"), + Ref::new("BracketedColumnReferenceListGrammar").optional(), + Ref::keyword("AS"), + optionally_bracketed(vec_of_erased![Ref::new("SelectableGrammar")]), + Ref::new("WithCheckOptionSegment").optional(), + ]) + .to_matchable() + .into(), + ), + ( + // An `ON DUPLICATE KEY UPDATE` statement. + // As specified in https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html + "UpsertClauseListSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("ON"), + Ref::keyword("DUPLICATE"), + Ref::keyword("KEY"), + Ref::keyword("UPDATE"), + Delimited::new(vec_of_erased![Ref::new("SetClauseSegment")]) + ]) + .to_matchable() + .into(), + ), + ( + // A row alias segment (used in `INSERT` statements). + // As specified in https://dev.mysql.com/doc/refman/8.0/en/insert.html + "InsertRowAliasSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("AS"), + Ref::new("SingleIdentifierGrammar"), + Bracketed::new(vec_of_erased![Ref::new("SingleIdentifierListSegment")]) + .config(|this| this.optional()) + ]) + .to_matchable() + .into(), + ), + ( + // A `Flush` statement. + // As per https://dev.mysql.com/doc/refman/8.0/en/flush.html + "FlushStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("FLUSH"), + one_of(vec_of_erased![ + Ref::keyword("NO_WRITE_TO_BINLOG"), + Ref::keyword("LOCAL"), + ]) + .config(|this| this.optional()), + one_of(vec_of_erased![ + Delimited::new(vec_of_erased![ + Sequence::new(vec_of_erased![Ref::keyword("BINARY"), Ref::keyword("LOGS")]), + Sequence::new(vec_of_erased![Ref::keyword("ENGINE"), Ref::keyword("LOGS")]), + Sequence::new(vec_of_erased![Ref::keyword("ERROR"), Ref::keyword("LOGS")]), + Sequence::new(vec_of_erased![ + Ref::keyword("GENERAL"), + Ref::keyword("LOGS") + ]), + Ref::keyword("HOSTS"), + Ref::keyword("LOGS"), + Ref::keyword("PRIVILEGES"), + Ref::keyword("OPTIMIZER_COSTS"), + Sequence::new(vec_of_erased![ + Ref::keyword("RELAY"), + Ref::keyword("LOGS"), + Sequence::new(vec_of_erased![ + Ref::keyword("FOR"), + Ref::keyword("CHANNEL"), + Ref::new("ObjectReferenceSegment") + ]) + .config(|this| this.optional()) + ]), + Sequence::new(vec_of_erased![Ref::keyword("SLOW"), Ref::keyword("LOGS")]), + Ref::keyword("STATUS"), + Ref::keyword("USER_RESOURCES") + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("TABLES"), + Sequence::new(vec_of_erased![ + Delimited::new(vec_of_erased![Ref::new("TableReferenceSegment")]) + .config( + |this| this.terminators = vec_of_erased![Ref::keyword("WITH")] + ), + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("WITH"), + Ref::keyword("READ"), + Ref::keyword("LOCK") + ]) + .config(|this| this.optional()) + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("TABLES"), + Sequence::new(vec_of_erased![ + Delimited::new(vec_of_erased![Ref::new("TableReferenceSegment")]) + .config( + |this| this.terminators = vec_of_erased![Ref::keyword("FOR")] + ), + ]), + Sequence::new(vec_of_erased![Ref::keyword("FOR"), Ref::keyword("EXPORT")]) + .config(|this| this.optional()) + ]) + ]) + ]) + .to_matchable() + .into(), + ), + ( + // A `LOAD DATA` statement. + // As specified in https://dev.mysql.com/doc/refman/8.0/en/load-data.html + "LoadDataSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("LOAD"), + Ref::keyword("DATA"), + one_of(vec_of_erased![ + Ref::keyword("LOW_PRIORITY"), + Ref::keyword("CONCURRENT") + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![Ref::keyword("LOCAL")]).config(|this| this.optional()), + Ref::keyword("INFILE"), + Ref::new("QuotedLiteralSegment"), + one_of(vec_of_erased![ + Ref::keyword("REPLACE"), + Ref::keyword("IGNORE") + ]) + .config(|this| this.optional()), + Ref::keyword("INTO"), + Ref::keyword("TABLE"), + Ref::new("TableReferenceSegment"), + Ref::new("SelectPartitionClauseSegment").optional(), + Sequence::new(vec_of_erased![ + Ref::keyword("CHARACTER"), + Ref::keyword("SET"), + Ref::new("NakedIdentifierSegment") + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + one_of(vec_of_erased![ + Ref::keyword("FIELDS"), + Ref::keyword("COLUMNS") + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("TERMINATED"), + Ref::keyword("BY"), + Ref::new("QuotedLiteralSegment") + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + Sequence::new(vec_of_erased![Ref::keyword("OPTIONALLY")]) + .config(|this| this.optional()), + Ref::keyword("ENCLOSED"), + Ref::keyword("BY"), + Ref::new("QuotedLiteralSegment") + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("ESCAPED"), + Ref::keyword("BY"), + Ref::new("QuotedLiteralSegment") + ]) + .config(|this| this.optional()) + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("LINES"), + Sequence::new(vec_of_erased![ + Ref::keyword("STARTING"), + Ref::keyword("BY"), + Ref::new("QuotedLiteralSegment") + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("TERMINATED"), + Ref::keyword("BY"), + Ref::new("QuotedLiteralSegment") + ]) + .config(|this| this.optional()) + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("IGNORE"), + Ref::new("NumericLiteralSegment"), + one_of(vec_of_erased![Ref::keyword("LINES"), Ref::keyword("ROWS")]) + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![Bracketed::new(vec_of_erased![ + Delimited::new(vec_of_erased![Ref::new("ColumnReferenceSegment")]) + ])]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("SET"), + Ref::new("Expression_B_Grammar") + ]) + .config(|this| this.optional()) + ]) + .to_matchable() + .into(), + ), + ( + // A `REPLACE` statement. + // As specified in https://dev.mysql.com/doc/refman/8.0/en/replace.html + "ReplaceSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("REPLACE"), + one_of(vec_of_erased![ + Ref::keyword("LOW_PRIORITY"), + Ref::keyword("DELAYED") + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![Ref::keyword("INTO")]).config(|this| this.optional()), + Ref::new("TableReferenceSegment"), + Ref::new("SelectPartitionClauseSegment").optional(), + one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::new("BracketedColumnReferenceListGrammar").optional(), + Ref::new("ValuesClauseSegment") + ]), + Ref::new("SetClauseListSegment"), + Sequence::new(vec_of_erased![ + Ref::new("BracketedColumnReferenceListGrammar").optional(), + one_of(vec_of_erased![ + Ref::new("SelectableGrammar"), + Sequence::new(vec_of_erased![ + Ref::keyword("TABLE"), + Ref::new("TableReferenceSegment") + ]) + ]) + ]) + ]) + ]) + .to_matchable() + .into(), + ), + ( + // An `ALTER DATABASE` statement. + // As specified in https://dev.mysql.com/doc/refman/8.0/en/alter-database.html + "AlterDatabaseStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("ALTER"), + one_of(vec_of_erased![ + Ref::keyword("DATABASE"), + Ref::keyword("SCHEMA") + ]), + Ref::new("DatabaseReferenceSegment").optional(), + AnyNumberOf::new(vec_of_erased![Ref::new("AlterOptionSegment")]) + ]) + .to_matchable() + .into(), + ), + ( + // A `RETURN` statement. + // As specified in https://dev.mysql.com/doc/refman/8.0/en/return.html + "ReturnStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("RETURN"), + Ref::new("ExpressionSegment") + ]) + .to_matchable() + .into(), + ), + ( + // A `SET NAMES` statement. + // As specified in https://dev.mysql.com/doc/refman/8.0/en/set-names.html + "SetNamesStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("SET"), + Ref::keyword("NAMES"), + one_of(vec_of_erased![ + Ref::keyword("DEFAULT"), + Ref::new("QuotedLiteralSegment"), + Ref::new("NakedIdentifierSegment") + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("COLLATE"), + Ref::new("CollationReferenceSegment") + ]) + .config(|this| this.optional()) + ]) + .to_matchable() + .into(), + ), + ( + // A `CREATE EVENT` statement. + // As specified in https://dev.mysql.com/doc/refman/9.2/en/create-event.html + "CreateEventStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("CREATE"), + Ref::new("DefinerSegment").optional(), + Ref::keyword("EVENT"), + Ref::new("IfNotExistsGrammar").optional(), + Ref::new("ObjectReferenceSegment"), + Ref::keyword("ON"), + Ref::keyword("SCHEDULE"), + one_of(vec_of_erased![Ref::keyword("AT"), Ref::keyword("EVERY")]), + Ref::new("ExpressionSegment"), + one_of(vec_of_erased![Ref::new("DatetimeUnitSegment")]) + .config(|this| this.optional()), + AnyNumberOf::new(vec_of_erased![Sequence::new(vec_of_erased![ + one_of(vec_of_erased![Ref::keyword("STARTS"), Ref::keyword("ENDS")]), + Ref::new("ExpressionSegment") + ])]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("ON"), + Ref::keyword("COMPLETION"), + Ref::keyword("NOT").optional(), + Ref::keyword("PRESERVE") + ]) + .config(|this| this.optional()), + one_of(vec_of_erased![ + Ref::keyword("ENABLE"), + Ref::keyword("DISABLE"), + Sequence::new(vec_of_erased![ + Ref::keyword("DISABLE"), + Ref::keyword("ON"), + one_of(vec_of_erased![ + Ref::keyword("REPLICA"), + Ref::keyword("SLAVE") + ]) + ]) + ]) + .config(|this| this.optional()), + Ref::new("CommentClauseSegment").optional(), + Ref::keyword("DO"), + Ref::new("StatementSegment") + ]) + .to_matchable() + .into(), + ), + ( + // An `ALTER EVENT` statement. + // As specified in https://dev.mysql.com/doc/refman/9.2/en/alter-event.html + "AlterEventStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("ALTER"), + Ref::new("DefinerSegment").optional(), + Ref::keyword("EVENT"), + Ref::new("ObjectReferenceSegment"), + Sequence::new(vec_of_erased![ + Ref::keyword("ON"), + Ref::keyword("SCHEDULE"), + one_of(vec_of_erased![Ref::keyword("AT"), Ref::keyword("EVERY")]), + Ref::new("ExpressionSegment"), + one_of(vec_of_erased![Ref::new("DatetimeUnitSegment")]) + .config(|this| this.optional()), + AnyNumberOf::new(vec_of_erased![Sequence::new(vec_of_erased![ + one_of(vec_of_erased![Ref::keyword("STARTS"), Ref::keyword("ENDS")]), + Ref::new("ExpressionSegment") + ])]) + .config(|this| this.optional()) + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("ON"), + Ref::keyword("COMPLETION"), + Ref::keyword("NOT").optional(), + Ref::keyword("PRESERVE") + ]) + .config(|this| this.optional()), + Sequence::new(vec_of_erased![ + Ref::keyword("RENAME"), + Ref::keyword("TO"), + Ref::new("ObjectReferenceSegment") + ]) + .config(|this| this.optional()), + one_of(vec_of_erased![ + Ref::keyword("ENABLE"), + Ref::keyword("DISABLE"), + Sequence::new(vec_of_erased![ + Ref::keyword("DISABLE"), + Ref::keyword("ON"), + one_of(vec_of_erased![ + Ref::keyword("REPLICA"), + Ref::keyword("SLAVE") + ]) + ]) + ]) + .config(|this| this.optional()), + Ref::new("CommentClauseSegment").optional(), + Sequence::new(vec_of_erased![ + Ref::keyword("DO"), + Ref::new("StatementSegment") + ]) + .config(|this| this.optional()) + ]) + .to_matchable() + .into(), + ), + ( + // A `DROP EVENT` statement. + // As specified in https://dev.mysql.com/doc/refman/9.2/en/drop-event.html + "DropEventStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("DROP"), + Ref::keyword("EVENT"), + Ref::new("IfExistsGrammar").optional(), + Ref::new("ObjectReferenceSegment") + ]) + .to_matchable() + .into(), + ), + ( + // This is the body of a `CREATE FUNCTION` and `CREATE TRIGGER` statements. + "DefinerSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("DEFINER"), + Ref::new("EqualsSegment"), + Ref::new("RoleReferenceSegment"), + ]) + .to_matchable() + .into(), + ), + ( + // This is the body of a partition clause. + "SelectPartitionClauseSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("PARTITION"), + Bracketed::new(vec_of_erased![Delimited::new(vec_of_erased![Ref::new( + "ObjectReferenceSegment" + )])]) + ]) + .to_matchable() + .into(), + ), + ( + // A database characteristic. + // As specified in https://dev.mysql.com/doc/refman/8.0/en/alter-database.html + "AlterOptionSegment".into(), + Sequence::new(vec_of_erased![one_of(vec_of_erased![ + Sequence::new(vec_of_erased![ + Ref::keyword("DEFAULT").optional(), + Ref::keyword("CHARACTER"), + Ref::keyword("SET"), + Ref::new("EqualsSegment").optional(), + Ref::new("NakedIdentifierSegment"), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("DEFAULT").optional(), + Ref::keyword("COLLATE"), + Ref::new("EqualsSegment").optional(), + Ref::new("CollationReferenceSegment"), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("DEFAULT").optional(), + Ref::keyword("ENCRYPTION"), + Ref::new("EqualsSegment").optional(), + Ref::new("QuotedLiteralSegment"), + ]), + Sequence::new(vec_of_erased![ + Ref::keyword("READ"), + Ref::keyword("ONLY"), + Ref::new("EqualsSegment").optional(), + one_of(vec_of_erased![ + Ref::keyword("DEFAULT"), + Ref::new("NumericLiteralSegment"), + ]), + ]), + ]),]) + .to_matchable() + .into(), + ), + ( + // A WITH CHECK OPTION segment for CREATE/ALTER View Syntax. + // As specified in https://dev.mysql.com/doc/refman/8.0/en/alter-view.html + "WithCheckOptionSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("WITH"), + one_of(vec_of_erased![ + Ref::keyword("CASCADED"), + Ref::keyword("LOCAL"), + ]) + .config(|one_of| one_of.optional()), + Ref::keyword("CHECK"), + Ref::keyword("OPTION"), + ]) + .to_matchable() + .into(), + ), + ]); + + mysql.replace_grammar( + "StatementSegment", + ansi::statement_segment().copy( + Some(vec_of_erased![ + Ref::new("DelimiterStatement"), + Ref::new("CreateProcedureStatementSegment"), + Ref::new("DeclareStatement"), + Ref::new("SetTransactionStatementSegment"), + Ref::new("SetAssignmentStatementSegment"), + Ref::new("IfExpressionStatement"), + Ref::new("WhileStatementSegment"), + Ref::new("IterateStatementSegment"), + Ref::new("RepeatStatementSegment"), + Ref::new("LoopStatementSegment"), + Ref::new("CallStoredProcedureSegment"), + Ref::new("PrepareSegment"), + Ref::new("ExecuteSegment"), + Ref::new("DeallocateSegment"), + Ref::new("GetDiagnosticsSegment"), + Ref::new("ResignalSegment"), + Ref::new("CursorOpenCloseSegment"), + Ref::new("CursorFetchSegment"), + Ref::new("DropProcedureStatementSegment"), + Ref::new("AlterTableStatementSegment"), + Ref::new("AlterViewStatementSegment"), + Ref::new("CreateViewStatementSegment"), + Ref::new("RenameTableStatementSegment"), + Ref::new("ResetMasterStatementSegment"), + Ref::new("PurgeBinaryLogsStatementSegment"), + Ref::new("HelpStatementSegment"), + Ref::new("CheckTableStatementSegment"), + Ref::new("ChecksumTableStatementSegment"), + Ref::new("AnalyzeTableStatementSegment"), + Ref::new("RepairTableStatementSegment"), + Ref::new("OptimizeTableStatementSegment"), + Ref::new("UpsertClauseListSegment"), + Ref::new("InsertRowAliasSegment"), + Ref::new("FlushStatementSegment"), + Ref::new("LoadDataSegment"), + Ref::new("ReplaceSegment"), + Ref::new("AlterDatabaseStatementSegment"), + Ref::new("ReturnStatementSegment"), + Ref::new("SetNamesStatementSegment"), + Ref::new("CreateEventStatementSegment"), + Ref::new("AlterEventStatementSegment"), + Ref::new("DropEventStatementSegment"), + ]), + None, + None, + Some(vec_of_erased![ + // handle CREATE SCHEMA in CreateDatabaseStatementSegment + Ref::new("CreateSchemaStatementSegment"), + ]), + Vec::new(), + false, + ), + ); + mysql } diff --git a/crates/lib-dialects/src/mysql_keywords.rs b/crates/lib-dialects/src/mysql_keywords.rs new file mode 100644 index 000000000..f08bc2bbe --- /dev/null +++ b/crates/lib-dialects/src/mysql_keywords.rs @@ -0,0 +1,787 @@ +///A List of MySQL SQL keywords. +///https://dev.mysql.com/doc/refman/8.0/en/keywords.html + +pub(crate) const MYSQL_RESERVED_KEYWORDS: &str = "ACCESSIBLE +ADD +ALL +ALTER +ANALYZE +AND +AS +ASC +ASENSITIVE +BEFORE +BETWEEN +BIGINT +BINARY +BLOB +BOTH +BY +CALL +CASCADE +CASE +CHANGE +CHAR +CHARACTER +CHECK +COLLATE +COLUMN +CONDITION +CONSTRAINT +CONTINUE +CONVERT +CREATE +CROSS +CUME_DIST +CURRENT_DATE +CURRENT_TIME +CURRENT_TIMESTAMP +CURRENT_USER +CURSOR +DATABASE +DATABASES +DAY_HOUR +DAY_MICROSECOND +DAY_MINUTE +DAY_SECOND +DEC +DECIMAL +DECLARE +DEFAULT +DELAYED +DELETE +DENSE_RANK +DESC +DESCRIBE +DETERMINISTIC +DISTINCT +DISTINCTROW +DIV +DOUBLE +DROP +DUAL +EACH +ELSE +ELSEIF +EMPTY +ENCLOSED +ESCAPED +EXCEPT +EXISTS +EXIT +EXPLAIN +FALSE +FETCH +FIRST_VALUE +FLOAT +FLOAT4 +FLOAT8 +FOR +FORCE +FOREIGN +FROM +FULLTEXT +GENERATED +GET +GRANT +GROUP +GROUPING +GROUPS +HAVING +HIGH_PRIORITY +HOUR_MICROSECOND +HOUR_MINUTE +HOUR_SECOND +IF +IGNORE +IN +INDEX +INFILE +INNER +INOUT +INSENSITIVE +INSERT +INT +INT1 +INT2 +INT3 +INT4 +INT8 +INTEGER +INTERSECT +INTERVAL +INTO +IO_AFTER_GTIDS +IO_BEFORE_GTIDS +IS +ITERATE +JOIN +JSON_TABLE +KEY +KEYS +KILL +LAG +LAST_VALUE +LATERAL +LEAD +LEADING +LEAVE +LEFT +LIKE +LIMIT +LINEAR +LINES +LOAD +LOCALTIME +LOCALTIMESTAMP +LOCK +LONG +LONGBLOB +LONGTEXT +LOOP +LOW_PRIORITY +MASTER_BIND +MASTER_SSL_VERIFY_SERVER_CERT +MATCH +MAXVALUE +MEDIUMBLOB +MEDIUMINT +MEDIUMTEXT +MIDDLEINT +MINUTE_MICROSECOND +MINUTE_SECOND +MOD +MODIFIES +NATURAL +NOT +NO_WRITE_TO_BINLOG +NTH_VALUE +NTILE +NULL +NUMERIC +OF +ON +OPTIMIZE +OPTIMIZER_COSTS +OPTION +OPTIONALLY +OR +ORDER +OUT +OUTER +OUTFILE +OVER +PARTITION +PERCENT_RANK +PRECISION +PRIMARY +PROCEDURE +PURGE +RANGE +RANK +READ +READS +READ_WRITE +REAL +RECURSIVE +REFERENCES +REGEXP +RELEASE +RENAME +REPEAT +REPLACE +REQUIRE +RESIGNAL +RESTRICT +RETURN +REVOKE +RIGHT +RLIKE +ROW_NUMBER +SCHEMA +SCHEMAS +SECOND_MICROSECOND +SELECT +SENSITIVE +SEPARATOR +SET +SHOW +SIGNAL +SMALLINT +SPATIAL +SPECIFIC +SQL +SQLEXCEPTION +SQLSTATE +SQLWARNING +SQL_BIG_RESULT +SQL_CALC_FOUND_ROWS +SQL_SMALL_RESULT +SSL +STARTING +STORED +STRAIGHT_JOIN +SYSTEM +TABLE +TERMINATED +THEN +TINYBLOB +TINYINT +TINYTEXT +TO +TRAILING +TRIGGER +TRUE +UNDO +UNION +UNIQUE +UNLOCK +UNSIGNED +UPDATE +USAGE +USE +USING +UTC_DATE +UTC_TIME +UTC_TIMESTAMP +VALUES +VARBINARY +VARCHAR +VARCHARACTER +VARYING +VIRTUAL +WHEN +WHERE +WHILE +WINDOW +WITH +WRITE +XOR +YEAR_MONTH +ZEROFILL +"; + +pub(crate) const MYSQL_UNRESERVED_KEYWORDS: &str = "ACCOUNT +ACTION +ACTIVE +ADMIN +AFTER +AGAINST +AGGREGATE +ALGORITHM +ALWAYS +ANALYSE +ANY +ARRAY +ASCII +AT +ATTRIBUTE +AUTHENTICATION +AUTOEXTEND_SIZE +AUTO_INCREMENT +AVG +AVG_ROW_LENGTH +BACKUP +BEGIN +BINLOG +BIT +BLOCK +BOOL +BOOLEAN +BTREE +BUCKETS +BYTE +CACHE +CASCADED +CATALOG_NAME +CHAIN +CHALLENGE_RESPONSE +CHANGED +CHANNEL +CHARSET +CHECKSUM +CIPHER +CLASS_ORIGIN +CLIENT +CLONE +CLOSE +COALESCE +CODE +COLLATION +COLUMNS +COLUMN_FORMAT +COLUMN_NAME +COMMENT +COMMIT +COMMITTED +COMPACT +COMPLETION +COMPONENT +COMPRESSED +COMPRESSION +CONCURRENT +CONNECTION +CONSISTENT +CONSTRAINT_CATALOG +CONSTRAINT_NAME +CONSTRAINT_SCHEMA +CONTAINS +CONTEXT +CPU +CUBE +CUME_DIST +CURRENT +CURSOR_NAME +DATA +DATAFILE +DATE +DATETIME +DAY +DEALLOCATE +DEFAULT_AUTH +DEFINER +DEFINITION +DELAY_KEY_WRITE +DENSE_RANK +DESCRIPTION +DES_KEY_FILE +DIAGNOSTICS +DIRECTORY +DISABLE +DISCARD +DISK +DO +DUMPFILE +DUPLICATE +DYNAMIC +EMPTY +ENABLE +ENCRYPTION +END +ENDS +ENFORCED +ENGINE +ENGINES +ENGINE_ATTRIBUTE +ENUM +ERROR +ERRORS +ESCAPE +EVENT +EVENTS +EVERY +EXCHANGE +EXCLUDE +EXECUTE +EXPANSION +EXPIRE +EXPORT +EXTENDED +EXTENT_SIZE +FACTOR +FAILED_LOGIN_ATTEMPTS +FAST +FAULTS +FIELDS +FILE +FILE_BLOCK_SIZE +FILTER +FINISH +FIRST +FIRST_VALUE +FIXED +FLUSH +FOLLOWING +FOLLOWS +FORMAT +FOUND +FULL +FUNCTION +GENERAL +GEOMCOLLECTION +GEOMETRY +GEOMETRYCOLLECTION +GET_FORMAT +GET_MASTER_PUBLIC_KEY +GET_SOURCE_PUBLIC_KEY +GLOBAL +GRANTS +GROUPING +GROUPS +GROUP_REPLICATION +GTID_ONLY +HANDLER +HASH +HELP +HISTOGRAM +HISTORY +HOST +HOSTS +HOUR +IDENTIFIED +IGNORE_SERVER_IDS +IMPORT +INACTIVE +INDEXES +INITIAL +INITIAL_SIZE +INITIATE +INSERT_METHOD +INSTALL +INSTANCE +INTERSECT +INVISIBLE +INVOKER +IO +IO_THREAD +IPC +ISOLATION +ISSUER +JSON +JSON_TABLE +JSON_VALUE +KEYRING +KEY_BLOCK_SIZE +LAG +LANGUAGE +LAST +LAST_VALUE +LATERAL +LEAD +LEAVES +LESS +LEVEL +LINESTRING +LIST +LOCAL +LOCKED +LOCKS +LOGFILE +LOGS +MASTER +MASTER_AUTO_POSITION +MASTER_COMPRESSION_ALGORITHMS +MASTER_CONNECT_RETRY +MASTER_DELAY +MASTER_HEARTBEAT_PERIOD +MASTER_HOST +MASTER_LOG_FILE +MASTER_LOG_POS +MASTER_PASSWORD +MASTER_PORT +MASTER_PUBLIC_KEY_PATH +MASTER_RETRY_COUNT +MASTER_SERVER_ID +MASTER_SSL +MASTER_SSL_CA +MASTER_SSL_CAPATH +MASTER_SSL_CERT +MASTER_SSL_CIPHER +MASTER_SSL_CRL +MASTER_SSL_CRLPATH +MASTER_SSL_KEY +MASTER_TLS_CIPHERSUITES +MASTER_TLS_VERSION +MASTER_USER +MASTER_ZSTD_COMPRESSION_LEVEL +MAX_CONNECTIONS_PER_HOUR +MAX_QUERIES_PER_HOUR +MAX_ROWS +MAX_SIZE +MAX_UPDATES_PER_HOUR +MAX_USER_CONNECTIONS +MEDIUM +MEMBER +MEMORY +MERGE +MESSAGE_TEXT +MICROSECOND +MIGRATE +MINUTE +MIN_ROWS +MODE +MODIFY +MONTH +MULTILINESTRING +MULTIPOINT +MULTIPOLYGON +MUTEX +MYSQL_ERRNO +NAME +NAMES +NATIONAL +NCHAR +NDB +NDBCLUSTER +NESTED +NETWORK_NAMESPACE +NEVER +NEW +NEXT +NO +NODEGROUP +NONE +NOWAIT +NO_WAIT +NTH_VALUE +NTILE +NULLS +NUMBER +NVARCHAR +OF +OFF +OFFSET +OJ +OLD +ONE +ONLY +OPEN +OPTIONAL +OPTIONS +ORDINALITY +ORGANIZATION +OTHERS +OVER +OWNER +PACK_KEYS +PAGE +PARSER +PARSE_GCOL_EXPR +PARTIAL +PARTITIONING +PARTITIONS +PASSWORD +PASSWORD_LOCK_TIME +PATH +PERCENT_RANK +PERSIST +PERSIST_ONLY +PHASE +PLUGIN +PLUGINS +PLUGIN_DIR +POINT +POLYGON +PORT +PRECEDES +PRECEDING +PREPARE +PRESERVE +PREV +PRIVILEGES +PRIVILEGE_CHECKS_USER +PROCESS +PROCESSLIST +PROFILE +PROFILES +PROXY +QUARTER +QUERY +QUICK +RANDOM +RANK +READ_ONLY +REBUILD +RECOVER +RECURSIVE +REDOFILE +REDO_BUFFER_SIZE +REDUNDANT +REFERENCE +REGISTRATION +RELAY +RELAYLOG +RELAY_LOG_FILE +RELAY_LOG_POS +RELAY_THREAD +RELOAD +REMOTE +REMOVE +REORGANIZE +REPAIR +REPEATABLE +REPLICA +REPLICAS +REPLICATE_DO_DB +REPLICATE_DO_TABLE +REPLICATE_IGNORE_DB +REPLICATE_IGNORE_TABLE +REPLICATE_REWRITE_DB +REPLICATE_WILD_DO_TABLE +REPLICATE_WILD_IGNORE_TABLE +REPLICATION +REQUIRE_ROW_FORMAT +RESET +RESOURCE +RESPECT +RESTART +RESTORE +RESUME +RETAIN +RETURNED_SQLSTATE +RETURNING +RETURNS +REUSE +REVERSE +ROLE +ROLLBACK +ROLLUP +ROTATE +ROUTINE +ROW +ROWS +ROW_COUNT +ROW_FORMAT +ROW_NUMBER +RTREE +SAVEPOINT +SCHEDULE +SCHEMA_NAME +SECOND +SECONDARY +SECONDARY_ENGINE +SECONDARY_ENGINE_ATTRIBUTE +SECONDARY_LOAD +SECONDARY_UNLOAD +SECURITY +SERIAL +SERIALIZABLE +SERVER +SESSION +SHARE +SHUTDOWN +SIGNED +SIMPLE +SKIP +SLAVE +SLOW +SNAPSHOT +SOCKET +SOME +SONAME +SOUNDS +SOURCE +SOURCE_AUTO_POSITION +SOURCE_BIND +SOURCE_COMPRESSION_ALGORITHMS +SOURCE_CONNECT_RETRY +SOURCE_DELAY +SOURCE_HEARTBEAT_PERIOD +SOURCE_HOST +SOURCE_LOG_FILE +SOURCE_LOG_POS +SOURCE_PASSWORD +SOURCE_PORT +SOURCE_PUBLIC_KEY_PATH +SOURCE_RETRY_COUNT +SOURCE_SSL +SOURCE_SSL_CA +SOURCE_SSL_CAPATH +SOURCE_SSL_CERT +SOURCE_SSL_CIPHER +SOURCE_SSL_CRL +SOURCE_SSL_CRLPATH +SOURCE_SSL_KEY +SOURCE_SSL_VERIFY_SERVER_CERT +SOURCE_TLS_CIPHERSUITES +SOURCE_TLS_VERSION +SOURCE_USER +SOURCE_ZSTD_COMPRESSION_LEVEL +SQL_AFTER_GTIDS +SQL_AFTER_MTS_GAPS +SQL_BEFORE_GTIDS +SQL_BUFFER_RESULT +SQL_CACHE +SQL_NO_CACHE +SQL_THREAD +SQL_TSI_DAY +SQL_TSI_HOUR +SQL_TSI_MINUTE +SQL_TSI_MONTH +SQL_TSI_QUARTER +SQL_TSI_SECOND +SQL_TSI_WEEK +SQL_TSI_YEAR +SRID +STACKED +START +STARTS +STATS_AUTO_RECALC +STATS_PERSISTENT +STATS_SAMPLE_PAGES +STATUS +STOP +STORAGE +STREAM +STRING +SUBCLASS_ORIGIN +SUBJECT +SUBPARTITION +SUBPARTITIONS +SUPER +SUSPEND +SWAPS +SWITCHES +SYSTEM +TABLES +TABLESPACE +TABLE_CHECKSUM +TABLE_NAME +TEMPORARY +TEMPTABLE +TEXT +THAN +THREAD_PRIORITY +TIES +TIME +TIMESTAMP +TIMESTAMPADD +TIMESTAMPDIFF +TLS +TRANSACTION +TRIGGERS +TRUNCATE +TYPE +TYPES +UNBOUNDED +UNCOMMITTED +UNDEFINED +UNDOFILE +UNDO_BUFFER_SIZE +UNICODE +UNINSTALL +UNKNOWN +UNREGISTER +UNTIL +UPGRADE +USER +USER_RESOURCES +USE_FRM +VALIDATION +VALUE +VARIABLES +VCPU +VIEW +VISIBLE +WAIT +WARNINGS +WEEK +WEIGHT_STRING +WINDOW +WITHOUT +WORK +WRAPPER +X509 +XA +XID +XML +YEAR +ZONE +NOW +SHARED +INPLACE +NOCOPY +INSTANT +"; +// These are not all MySQL keywords, but sqruff needs them to parse well. +// Anything past NOW and including NOW is not a MySQL keyword. diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/alter_database.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_database.sql new file mode 100644 index 000000000..e8e3a90c5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_database.sql @@ -0,0 +1,26 @@ +ALTER DATABASE my_database +DEFAULT CHARACTER SET utf8mb4 +COLLATE utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION 'N'; + +ALTER DATABASE my_database +DEFAULT CHARACTER SET = utf8mb4 +COLLATE = utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION = 'N'; + +ALTER SCHEMA my_database +DEFAULT CHARACTER SET utf8mb4 +COLLATE utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION 'N'; + +ALTER DATABASE my_database +READ ONLY DEFAULT; + +ALTER DATABASE my_database +READ ONLY 0; + +ALTER DATABASE my_database +READ ONLY 1; + +ALTER DATABASE +READ ONLY DEFAULT; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/alter_database.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_database.yml new file mode 100644 index 000000000..2f6f279ce --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_database.yml @@ -0,0 +1,89 @@ +file: +- statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - keyword: DEFAULT + - keyword: CHARACTER + - keyword: SET + - naked_identifier: utf8mb4 + - keyword: COLLATE + - collation_reference: + - naked_identifier: utf8mb4_0900_ai_ci + - keyword: DEFAULT + - keyword: ENCRYPTION + - quoted_literal: '''N''' +- statement_terminator: ; +- statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - keyword: DEFAULT + - keyword: CHARACTER + - keyword: SET + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: utf8mb4 + - keyword: COLLATE + - comparison_operator: + - raw_comparison_operator: = + - collation_reference: + - naked_identifier: utf8mb4_0900_ai_ci + - keyword: DEFAULT + - keyword: ENCRYPTION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''N''' +- statement_terminator: ; +- statement: + - keyword: ALTER + - keyword: SCHEMA + - database_reference: + - naked_identifier: my_database + - keyword: DEFAULT + - keyword: CHARACTER + - keyword: SET + - naked_identifier: utf8mb4 + - keyword: COLLATE + - collation_reference: + - naked_identifier: utf8mb4_0900_ai_ci + - keyword: DEFAULT + - keyword: ENCRYPTION + - quoted_literal: '''N''' +- statement_terminator: ; +- statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - keyword: READ + - keyword: ONLY + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - keyword: READ + - keyword: ONLY + - numeric_literal: '0' +- statement_terminator: ; +- statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - keyword: READ + - keyword: ONLY + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - keyword: ALTER + - keyword: DATABASE + - keyword: READ + - keyword: ONLY + - keyword: DEFAULT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/alter_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_table.sql new file mode 100644 index 000000000..11eb0ce82 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_table.sql @@ -0,0 +1,77 @@ +ALTER TABLE `users` + MODIFY COLUMN + `name` varchar(255) NOT NULL, + COMMENT "name of user"; + +ALTER TABLE `users` MODIFY `name` varchar(255) NOT NULL FIRST; + +ALTER TABLE `users` RENAME TO `user`; + +ALTER TABLE `user` RENAME AS `users`; + +ALTER TABLE `users` RENAME `user`; + +ALTER TABLE `users` RENAME COLUMN `col_1` TO `del_col_1`; + +ALTER TABLE `users` +CHANGE COLUMN `birthday` `date_of_birth` INT(11) NULL DEFAULT NULL; + +ALTER TABLE `users` +CHANGE COLUMN `birthday` `date_of_birth` INT(11) NOT NULL; + +ALTER TABLE `users` +CHANGE COLUMN `birthday` `date_of_birth` INT(11) FIRST; + +ALTER TABLE `users` +CHANGE COLUMN `birthday` `date_of_birth` INT(11) AFTER `name`; + +ALTER TABLE `users` +DROP COLUMN `age`; + +ALTER TABLE `foo`.`bar` +ADD CONSTRAINT `index_name` UNIQUE(`col_1`, `col_2`, `col_3`); + +ALTER TABLE `foo`.`bar` ADD UNIQUE `index_name`(`col_1`, `col_2`, `col_3`); + +ALTER TABLE `foo`.`bar` +ADD CONSTRAINT `index_name` UNIQUE INDEX (`col_1`, `col_2`, `col_3`); + +ALTER TABLE `foo`.`bar` +ADD UNIQUE INDEX `index_name`(`col_1`, `col_2`, `col_3`); + +ALTER TABLE `foo`.`bar` ADD INDEX `index_name`(`col_1`, `col_2`, `col_3`); + +ALTER TABLE `foo`.`bar` ADD INDEX `index_name`(`col_1`, `col_2`, `col_3`) +KEY_BLOCK_SIZE = 8; + +ALTER TABLE `foo`.`bar` ADD INDEX `index_name`(`col_1`, `col_2`, `col_3`) +KEY_BLOCK_SIZE 8; + +ALTER TABLE `foo`.`bar` ADD INDEX `index_name`(`col_1`, `col_2`, `col_3`) +KEY_BLOCK_SIZE 8 COMMENT 'index for col_1, col_2, col_3'; + +ALTER TABLE `foo`.`bar` DROP INDEX `index_name`; + +ALTER TABLE `foo`.`bar` RENAME INDEX `index_name` to `new_index_name`; + +ALTER TABLE `foo`.`bar` RENAME KEY `key_name` to `new_key_name`; + +ALTER TABLE `x` ADD CONSTRAINT FOREIGN KEY(`xk`) REFERENCES `y`(`yk`); + +ALTER TABLE `users` + ADD COLUMN `active` tinyint(1) DEFAULT '0'; + +ALTER TABLE `users` + ADD COLUMN IF NOT EXISTS `active` tinyint(1) DEFAULT '0'; + +ALTER TABLE `foo` ADD `bar` INT FIRST; + +ALTER TABLE `foo` ADD COLUMN d INT GENERATED ALWAYS AS (a*abs(b)) VIRTUAL; + +ALTER TABLE `foo` ADD COLUMN e TEXT GENERATED ALWAYS AS (substr(c,b,b+1)) STORED; + +ALTER TABLE `foo` ADD COLUMN d INT AS (a*abs(b)); + +ALTER TABLE `foo` ADD COLUMN e TEXT AS (substr(c,b,b+1)) STORED; + +ALTER TABLE `foo` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_table.yml new file mode 100644 index 000000000..15cef36f2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_table.yml @@ -0,0 +1,442 @@ +file: +- unparsable: + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: MODIFY + - word: COLUMN + - back_quote: '`name`' + - word: varchar + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - word: NOT + - word: 'NULL' + - comma: ',' + - word: COMMENT + - double_quote: '"name of user"' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: MODIFY + - back_quote: '`name`' + - word: varchar + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - word: NOT + - word: 'NULL' + - word: FIRST + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: RENAME + - word: TO + - back_quote: '`user`' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`user`' + - word: RENAME + - word: AS + - back_quote: '`users`' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: RENAME + - back_quote: '`user`' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: RENAME + - word: COLUMN + - back_quote: '`col_1`' + - word: TO + - back_quote: '`del_col_1`' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: CHANGE + - word: COLUMN + - back_quote: '`birthday`' + - back_quote: '`date_of_birth`' + - word: INT + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - word: 'NULL' + - word: DEFAULT + - word: 'NULL' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: CHANGE + - word: COLUMN + - back_quote: '`birthday`' + - back_quote: '`date_of_birth`' + - word: INT + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - word: NOT + - word: 'NULL' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: CHANGE + - word: COLUMN + - back_quote: '`birthday`' + - back_quote: '`date_of_birth`' + - word: INT + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - word: FIRST + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: CHANGE + - word: COLUMN + - back_quote: '`birthday`' + - back_quote: '`date_of_birth`' + - word: INT + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - word: AFTER + - back_quote: '`name`' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: DROP + - word: COLUMN + - back_quote: '`age`' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: ADD + - word: CONSTRAINT + - back_quote: '`index_name`' + - word: UNIQUE + - start_bracket: ( + - back_quote: '`col_1`' + - comma: ',' + - back_quote: '`col_2`' + - comma: ',' + - back_quote: '`col_3`' + - end_bracket: ) + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: ADD + - word: UNIQUE + - back_quote: '`index_name`' + - start_bracket: ( + - back_quote: '`col_1`' + - comma: ',' + - back_quote: '`col_2`' + - comma: ',' + - back_quote: '`col_3`' + - end_bracket: ) + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: ADD + - word: CONSTRAINT + - back_quote: '`index_name`' + - word: UNIQUE + - word: INDEX + - start_bracket: ( + - back_quote: '`col_1`' + - comma: ',' + - back_quote: '`col_2`' + - comma: ',' + - back_quote: '`col_3`' + - end_bracket: ) + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: ADD + - word: UNIQUE + - word: INDEX + - back_quote: '`index_name`' + - start_bracket: ( + - back_quote: '`col_1`' + - comma: ',' + - back_quote: '`col_2`' + - comma: ',' + - back_quote: '`col_3`' + - end_bracket: ) + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: ADD + - word: INDEX + - back_quote: '`index_name`' + - start_bracket: ( + - back_quote: '`col_1`' + - comma: ',' + - back_quote: '`col_2`' + - comma: ',' + - back_quote: '`col_3`' + - end_bracket: ) + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: ADD + - word: INDEX + - back_quote: '`index_name`' + - start_bracket: ( + - back_quote: '`col_1`' + - comma: ',' + - back_quote: '`col_2`' + - comma: ',' + - back_quote: '`col_3`' + - end_bracket: ) + - word: KEY_BLOCK_SIZE + - raw_comparison_operator: = + - numeric_literal: '8' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: ADD + - word: INDEX + - back_quote: '`index_name`' + - start_bracket: ( + - back_quote: '`col_1`' + - comma: ',' + - back_quote: '`col_2`' + - comma: ',' + - back_quote: '`col_3`' + - end_bracket: ) + - word: KEY_BLOCK_SIZE + - numeric_literal: '8' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: ADD + - word: INDEX + - back_quote: '`index_name`' + - start_bracket: ( + - back_quote: '`col_1`' + - comma: ',' + - back_quote: '`col_2`' + - comma: ',' + - back_quote: '`col_3`' + - end_bracket: ) + - word: KEY_BLOCK_SIZE + - numeric_literal: '8' + - word: COMMENT + - single_quote: '''index for col_1, col_2, col_3''' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: DROP + - word: INDEX + - back_quote: '`index_name`' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: RENAME + - word: INDEX + - back_quote: '`index_name`' + - word: to + - back_quote: '`new_index_name`' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: RENAME + - word: KEY + - back_quote: '`key_name`' + - word: to + - back_quote: '`new_key_name`' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`x`' + - word: ADD + - word: CONSTRAINT + - word: FOREIGN + - word: KEY + - start_bracket: ( + - back_quote: '`xk`' + - end_bracket: ) + - word: REFERENCES + - back_quote: '`y`' + - start_bracket: ( + - back_quote: '`yk`' + - end_bracket: ) + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: ADD + - word: COLUMN + - back_quote: '`active`' + - word: tinyint + - start_bracket: ( + - numeric_literal: '1' + - end_bracket: ) + - word: DEFAULT + - single_quote: '''0''' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`users`' + - word: ADD + - word: COLUMN + - word: IF + - word: NOT + - word: EXISTS + - back_quote: '`active`' + - word: tinyint + - start_bracket: ( + - numeric_literal: '1' + - end_bracket: ) + - word: DEFAULT + - single_quote: '''0''' + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - word: ADD + - back_quote: '`bar`' + - word: INT + - word: FIRST + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - word: ADD + - word: COLUMN + - word: d + - word: INT + - word: GENERATED + - word: ALWAYS + - word: AS + - start_bracket: ( + - word: a + - star: '*' + - word: abs + - start_bracket: ( + - word: b + - end_bracket: ) + - end_bracket: ) + - word: VIRTUAL + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - word: ADD + - word: COLUMN + - word: e + - word: TEXT + - word: GENERATED + - word: ALWAYS + - word: AS + - start_bracket: ( + - word: substr + - start_bracket: ( + - word: c + - comma: ',' + - word: b + - comma: ',' + - word: b + - plus: + + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - word: STORED + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - word: ADD + - word: COLUMN + - word: d + - word: INT + - word: AS + - start_bracket: ( + - word: a + - star: '*' + - word: abs + - start_bracket: ( + - word: b + - end_bracket: ) + - end_bracket: ) + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - word: ADD + - word: COLUMN + - word: e + - word: TEXT + - word: AS + - start_bracket: ( + - word: substr + - start_bracket: ( + - word: c + - comma: ',' + - word: b + - comma: ',' + - word: b + - plus: + + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - word: STORED + - semicolon: ; + - word: ALTER + - word: TABLE + - back_quote: '`foo`' + - word: CONVERT + - word: TO + - word: CHARACTER + - word: SET + - word: utf8mb4 + - word: COLLATE + - word: utf8mb4_unicode_ci + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/alter_view.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_view.sql new file mode 100644 index 000000000..8f8e674e7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_view.sql @@ -0,0 +1,15 @@ +ALTER VIEW v2 AS +SELECT c, d FROM v1; + +ALTER VIEW v2 AS +(SELECT c, d FROM v1); + +ALTER VIEW v1 (c,d) AS +SELECT a,max(b) FROM t1 GROUP BY a; + +ALTER VIEW v2 AS +SELECT * FROM t2 WHERE s1 IN (SELECT s1 FROM t1) +WITH CHECK OPTION; + +ALTER VIEW v2 AS +SELECT 1 UNION SELECT 2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/alter_view.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_view.yml new file mode 100644 index 000000000..2086d6a1b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/alter_view.yml @@ -0,0 +1,163 @@ +file: +- statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: v1 +- statement_terminator: ; +- statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: v1 + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c + - comma: ',' + - column_reference: + - naked_identifier: d + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: max + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: a +- statement_terminator: ; +- statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: s1 + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: s1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - end_bracket: ) + - unparsable: + - word: WITH + - word: CHECK + - word: OPTION +- statement_terminator: ; +- statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - set_operator: + - keyword: UNION + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/analyze_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/analyze_table.sql new file mode 100644 index 000000000..cd38b8296 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/analyze_table.sql @@ -0,0 +1,39 @@ +ANALYZE TABLE some_table; + +ANALYZE TABLE some_table1, some_table2; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table1, some_table2; + +ANALYZE LOCAL TABLE some_table; + +ANALYZE LOCAL TABLE some_table1, some_table2; + +ANALYZE TABLE some_table UPDATE HISTOGRAM ON some_col; + +ANALYZE TABLE some_table UPDATE HISTOGRAM ON some_col1, some_col2; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table UPDATE HISTOGRAM ON some_col; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table UPDATE HISTOGRAM ON some_col1, some_col2; + +ANALYZE LOCAL TABLE some_table UPDATE HISTOGRAM ON some_col; + +ANALYZE LOCAL TABLE some_table UPDATE HISTOGRAM ON some_col1, some_col2; + +ANALYZE TABLE some_table UPDATE HISTOGRAM ON some_col WITH 10 BUCKETS; + +ANALYZE TABLE some_table UPDATE HISTOGRAM ON some_col1, some_col2 WITH 10 BUCKETS; + +ANALYZE TABLE some_table DROP HISTOGRAM ON some_col; + +ANALYZE TABLE some_table DROP HISTOGRAM ON some_col1, some_col2; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table DROP HISTOGRAM ON some_col; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table DROP HISTOGRAM ON some_col1, some_col2; + +ANALYZE LOCAL TABLE some_table DROP HISTOGRAM ON some_col; + +ANALYZE LOCAL TABLE some_table DROP HISTOGRAM ON some_col1, some_col2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/analyze_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/analyze_table.yml new file mode 100644 index 000000000..ae8425a39 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/analyze_table.yml @@ -0,0 +1,239 @@ +file: +- statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col + - keyword: WITH + - numeric_literal: '10' + - keyword: BUCKETS +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 + - keyword: WITH + - numeric_literal: '10' + - keyword: BUCKETS +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/begin.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/begin.sql new file mode 100644 index 000000000..221c86213 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/begin.sql @@ -0,0 +1,3 @@ +blocks:BEGIN +select 1; +END blocks~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/begin.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/begin.yml new file mode 100644 index 000000000..50b20381f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/begin.yml @@ -0,0 +1,11 @@ +file: +- unparsable: + - word: blocks + - colon: ':' + - word: BEGIN + - word: select + - numeric_literal: '1' + - semicolon: ; + - word: END + - word: blocks + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/bit_value_literal.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/bit_value_literal.sql new file mode 100644 index 000000000..1e94007fd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/bit_value_literal.sql @@ -0,0 +1,3 @@ +SELECT b'01'; +SELECT B'01'; +SELECT 0b01; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/bit_value_literal.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/bit_value_literal.yml new file mode 100644 index 000000000..759621d1b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/bit_value_literal.yml @@ -0,0 +1,29 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - data_type: + - data_type_identifier: b + - quoted_literal: '''01''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - data_type: + - data_type_identifier: B + - quoted_literal: '''01''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: '0b01' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/call_statement.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/call_statement.sql new file mode 100644 index 000000000..cc85e93c7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/call_statement.sql @@ -0,0 +1,6 @@ +CALL somefunction('a'); +CALL somefunction(test('something')); +CALL somefunction('test', @test1, test2, test3('test'), "test4"); +CALL somefunction(); +CALL `somefunction`('a'); +CALL testdb.testfunc(123); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/call_statement.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/call_statement.yml new file mode 100644 index 000000000..8938e6273 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/call_statement.yml @@ -0,0 +1,22 @@ +file: +- unparsable: + - word: CALL + - word: somefunction + - start_bracket: ( + - single_quote: '''a''' + - end_bracket: ) + - semicolon: ; + - word: CALL + - word: somefunction + - start_bracket: ( + - word: test + - start_bracket: ( + - single_quote: '''something''' + - end_bracket: ) + - end_bracket: ) + - semicolon: ; + - word: CALL + - word: somefunction + - start_bracket: ( + - single_quote: '''test''' + - comma: ',' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/check_constraint.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/check_constraint.sql new file mode 100644 index 000000000..ba42f8ed8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/check_constraint.sql @@ -0,0 +1,15 @@ +CREATE TABLE t1 +( + CHECK (c1 <> c2), + c1 INT CHECK (c1 > 10), + c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), + c3 INT CHECK (c3 < 100), + CONSTRAINT c1_nonzero CHECK (c1 <> 0), + CHECK (c1 > c3) +); + +ALTER TABLE t1 +ALTER CHECK c2_positive NOT ENFORCED; + +ALTER TABLE t1 +DROP CONSTRAINT c1_nonzero; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/check_constraint.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/check_constraint.yml new file mode 100644 index 000000000..a2c5f0c9c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/check_constraint.yml @@ -0,0 +1,77 @@ +file: +- unparsable: + - word: CREATE + - word: TABLE + - word: t1 + - start_bracket: ( + - word: CHECK + - start_bracket: ( + - word: c1 + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - word: c2 + - end_bracket: ) + - comma: ',' + - word: c1 + - word: INT + - word: CHECK + - start_bracket: ( + - word: c1 + - raw_comparison_operator: '>' + - numeric_literal: '10' + - end_bracket: ) + - comma: ',' + - word: c2 + - word: INT + - word: CONSTRAINT + - word: c2_positive + - word: CHECK + - start_bracket: ( + - word: c2 + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - word: c3 + - word: INT + - word: CHECK + - start_bracket: ( + - word: c3 + - raw_comparison_operator: < + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - word: CONSTRAINT + - word: c1_nonzero + - word: CHECK + - start_bracket: ( + - word: c1 + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - word: CHECK + - start_bracket: ( + - word: c1 + - raw_comparison_operator: '>' + - word: c3 + - end_bracket: ) + - end_bracket: ) + - semicolon: ; + - word: ALTER + - word: TABLE + - word: t1 + - word: ALTER + - word: CHECK + - word: c2_positive + - word: NOT + - word: ENFORCED + - semicolon: ; + - word: ALTER + - word: TABLE + - word: t1 + - word: DROP + - word: CONSTRAINT + - word: c1_nonzero + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/check_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/check_table.sql new file mode 100644 index 000000000..1d02e57ad --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/check_table.sql @@ -0,0 +1,25 @@ +CHECK TABLE some_table FOR UPGRADE; + +CHECK TABLE some_table1, some_table2 FOR UPGRADE; + +CHECK TABLE some_table QUICK; + +CHECK TABLE some_table1, some_table2 QUICK; + +CHECK TABLE some_table FAST; + +CHECK TABLE some_table1, some_table2 FAST; + +CHECK TABLE some_table MEDIUM; + +CHECK TABLE some_table1, some_table2 MEDIUM; + +CHECK TABLE some_table EXTENDED; + +CHECK TABLE some_table1, some_table2 EXTENDED; + +CHECK TABLE some_table CHANGED; + +CHECK TABLE some_table1, some_table2 CHANGED; + +CHECK TABLE some_table FAST QUICK; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/check_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/check_table.yml new file mode 100644 index 000000000..e0cef90ae --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/check_table.yml @@ -0,0 +1,113 @@ +file: +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: UPGRADE +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: FOR + - keyword: UPGRADE +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: QUICK +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: QUICK +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: FAST +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: FAST +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: MEDIUM +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: MEDIUM +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: EXTENDED +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: EXTENDED +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: CHANGED +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: CHANGED +- statement_terminator: ; +- statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: FAST + - keyword: QUICK +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/checksum_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/checksum_table.sql new file mode 100644 index 000000000..d0bd37b50 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/checksum_table.sql @@ -0,0 +1,7 @@ +CHECKSUM TABLE some_table QUICK; + +CHECKSUM TABLE some_table1, some_table2 QUICK; + +CHECKSUM TABLE some_table EXTENDED; + +CHECKSUM TABLE some_table1, some_table2 EXTENDED; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/checksum_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/checksum_table.yml new file mode 100644 index 000000000..f56cd4193 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/checksum_table.yml @@ -0,0 +1,35 @@ +file: +- statement: + - keyword: CHECKSUM + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: QUICK +- statement_terminator: ; +- statement: + - keyword: CHECKSUM + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: QUICK +- statement_terminator: ; +- statement: + - keyword: CHECKSUM + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: EXTENDED +- statement_terminator: ; +- statement: + - keyword: CHECKSUM + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: EXTENDED +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/close.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/close.sql new file mode 100644 index 000000000..3f1510e77 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/close.sql @@ -0,0 +1 @@ +CLOSE curcursor; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/close.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/close.yml new file mode 100644 index 000000000..ee68afdcc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/close.yml @@ -0,0 +1,5 @@ +file: +- statement: + - keyword: CLOSE + - naked_identifier: curcursor +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/close_qualified.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/close_qualified.sql new file mode 100644 index 000000000..281dac8fe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/close_qualified.sql @@ -0,0 +1 @@ +CLOSE `curcursor`; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/close_qualified.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/close_qualified.yml new file mode 100644 index 000000000..91cd3d786 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/close_qualified.yml @@ -0,0 +1,5 @@ +file: +- unparsable: + - word: CLOSE + - back_quote: '`curcursor`' + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/column_alias.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/column_alias.sql new file mode 100644 index 000000000..55d384371 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/column_alias.sql @@ -0,0 +1,4 @@ +SELECT 1 AS `one`; +SELECT 2 AS 'two'; +SELECT 3 AS "three"; +SELECT 4 AS "four""_with_escaped_double_quotes"; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/column_alias.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/column_alias.yml new file mode 100644 index 000000000..1d7ca3c80 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/column_alias.yml @@ -0,0 +1,40 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - unparsable: + - word: AS + - back_quote: '`one`' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - keyword: AS + - quoted_identifier: '''two''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '3' + - keyword: AS + - quoted_identifier: '"three"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '4' + - keyword: AS + - quoted_identifier: '"four"' + - unparsable: + - double_quote: '"_with_escaped_double_quotes"' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_database.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_database.sql new file mode 100644 index 000000000..5831b2456 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_database.sql @@ -0,0 +1,20 @@ +CREATE DATABASE my_database; + +CREATE DATABASE IF NOT EXISTS my_database; + +CREATE DATABASE my_database +DEFAULT CHARACTER SET utf8mb4 +COLLATE utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION 'N'; + +CREATE DATABASE my_database +DEFAULT CHARACTER SET = utf8mb4 +COLLATE = utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION = 'N'; + +CREATE SCHEMA my_database +DEFAULT CHARACTER SET utf8mb4 +COLLATE utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION 'N'; + +CREATE DATABASE IF NOT EXISTS xxx CHARACTER SET "utf8mb4" COLLATE "utf8mb4_bin"; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_database.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_database.yml new file mode 100644 index 000000000..c199b0b4d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_database.yml @@ -0,0 +1,76 @@ +file: +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - database_reference: + - naked_identifier: my_database +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database +- file: + - word: DEFAULT + - word: CHARACTER + - word: SET + - word: utf8mb4 + - word: COLLATE + - word: utf8mb4_0900_ai_ci + - word: DEFAULT + - word: ENCRYPTION + - single_quote: '''N''' + - semicolon: ; + - word: CREATE + - word: DATABASE + - word: my_database + - word: DEFAULT + - word: CHARACTER + - word: SET + - raw_comparison_operator: = + - word: utf8mb4 + - word: COLLATE + - raw_comparison_operator: = + - word: utf8mb4_0900_ai_ci + - word: DEFAULT + - word: ENCRYPTION + - raw_comparison_operator: = + - single_quote: '''N''' + - semicolon: ; + - word: CREATE + - word: SCHEMA + - word: my_database + - word: DEFAULT + - word: CHARACTER + - word: SET + - word: utf8mb4 + - word: COLLATE + - word: utf8mb4_0900_ai_ci + - word: DEFAULT + - word: ENCRYPTION + - single_quote: '''N''' + - semicolon: ; + - word: CREATE + - word: DATABASE + - word: IF + - word: NOT + - word: EXISTS + - word: xxx + - word: CHARACTER + - word: SET + - double_quote: '"utf8mb4"' + - word: COLLATE + - double_quote: '"utf8mb4_bin"' + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_index.sql new file mode 100644 index 000000000..ecfe09891 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_index.sql @@ -0,0 +1,14 @@ +CREATE INDEX idx ON tbl (col); +CREATE UNIQUE INDEX idx ON tbl (col); +CREATE FULLTEXT INDEX idx ON tbl (col); +CREATE SPATIAL INDEX idx ON tbl (col); +CREATE INDEX idx USING BTREE ON tbl (col); +CREATE INDEX idx USING HASH ON tbl (col); +CREATE INDEX idx ON tbl (col ASC); +CREATE INDEX idx ON tbl (col DESC); +CREATE INDEX part_of_name ON customer (name(10)); +CREATE INDEX idx ON tbl (col) ALGORITHM DEFAULT; +CREATE INDEX idx ON tbl (col) ALGORITHM NOCOPY; +CREATE INDEX idx ON tbl (col) ALGORITHM INSTANT; +CREATE INDEX idx ON tbl (col) LOCK DEFAULT; +CREATE INDEX idx ON tbl ((col1 + col2), (col1 - col2), col1); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_index.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_index.yml new file mode 100644 index 000000000..bec79a731 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_index.yml @@ -0,0 +1,172 @@ +file: +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - database_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: col + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: UNIQUE + - keyword: INDEX + - database_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: col + - end_bracket: ) +- statement_terminator: ; +- file: + - word: CREATE + - word: FULLTEXT + - word: INDEX + - word: idx + - word: ON + - word: tbl + - start_bracket: ( + - word: col + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: SPATIAL + - word: INDEX + - word: idx + - word: ON + - word: tbl + - start_bracket: ( + - word: col + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: INDEX + - word: idx + - word: USING + - word: BTREE + - word: ON + - word: tbl + - start_bracket: ( + - word: col + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: INDEX + - word: idx + - word: USING + - word: HASH + - word: ON + - word: tbl + - start_bracket: ( + - word: col + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: INDEX + - word: idx + - word: ON + - word: tbl + - start_bracket: ( + - word: col + - word: ASC + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: INDEX + - word: idx + - word: ON + - word: tbl + - start_bracket: ( + - word: col + - word: DESC + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: INDEX + - word: part_of_name + - word: ON + - word: customer + - start_bracket: ( + - word: name + - start_bracket: ( + - numeric_literal: '10' + - end_bracket: ) + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: INDEX + - word: idx + - word: ON + - word: tbl + - start_bracket: ( + - word: col + - end_bracket: ) + - word: ALGORITHM + - word: DEFAULT + - semicolon: ; + - word: CREATE + - word: INDEX + - word: idx + - word: ON + - word: tbl + - start_bracket: ( + - word: col + - end_bracket: ) + - word: ALGORITHM + - word: NOCOPY + - semicolon: ; + - word: CREATE + - word: INDEX + - word: idx + - word: ON + - word: tbl + - start_bracket: ( + - word: col + - end_bracket: ) + - word: ALGORITHM + - word: INSTANT + - semicolon: ; + - word: CREATE + - word: INDEX + - word: idx + - word: ON + - word: tbl + - start_bracket: ( + - word: col + - end_bracket: ) + - word: LOCK + - word: DEFAULT + - semicolon: ; + - word: CREATE + - word: INDEX + - word: idx + - word: ON + - word: tbl + - start_bracket: ( + - start_bracket: ( + - word: col1 + - plus: + + - word: col2 + - end_bracket: ) + - comma: ',' + - start_bracket: ( + - word: col1 + - minus: '-' + - word: col2 + - end_bracket: ) + - comma: ',' + - word: col1 + - end_bracket: ) + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_role.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_role.sql new file mode 100644 index 000000000..e00c1ec17 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_role.sql @@ -0,0 +1 @@ +CREATE ROLE IF NOT EXISTS 'example-role'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_role.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_role.yml new file mode 100644 index 000000000..da542f789 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_role.yml @@ -0,0 +1,9 @@ +file: +- unparsable: + - word: CREATE + - word: ROLE + - word: IF + - word: NOT + - word: EXISTS + - single_quote: '''example-role''' + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table.sql new file mode 100644 index 000000000..db0e5d89b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table.sql @@ -0,0 +1,35 @@ +CREATE TABLE `foo` ( + b VARCHAR(255) BINARY, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +create table `tickets` ( + `id` serial primary key, + `material_number` varchar(255) default null, + `material_name` varchar(255) default null, + `date_created` date not null default (current_date), + `date_closed` date default null +); + +create table _ (a int); + +CREATE TABLE foo SELECT * FROM bar; + +CREATE TEMPORARY TABLE tbl_name ( + id INT PRIMARY KEY AUTO_INCREMENT, + col VARCHAR(255) DEFAULT '' NOT NULL, + INDEX(col) +) AS SELECT id, col FROM table_name; + +CREATE TEMPORARY TABLE tbl_name ( + id INT PRIMARY KEY AUTO_INCREMENT, + col VARCHAR(255) DEFAULT '' NOT NULL, + INDEX(col) +) SELECT id, col FROM table_name; + +CREATE TEMPORARY TABLE tbl_name (INDEX(col)) AS + SELECT id, col FROM table_name; + +CREATE TEMPORARY TABLE tbl_name (INDEX(col)) + SELECT id, col FROM table_name; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table.yml new file mode 100644 index 000000000..55676d756 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table.yml @@ -0,0 +1,198 @@ +file: +- unparsable: + - word: CREATE + - word: TABLE + - back_quote: '`foo`' + - start_bracket: ( + - word: b + - word: VARCHAR + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - word: BINARY + - comma: ',' + - back_quote: '`id`' + - word: int + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - word: unsigned + - word: NOT + - word: 'NULL' + - word: AUTO_INCREMENT + - comma: ',' + - word: PRIMARY + - word: KEY + - start_bracket: ( + - back_quote: '`id`' + - end_bracket: ) + - end_bracket: ) + - word: ENGINE + - raw_comparison_operator: = + - word: InnoDB + - word: DEFAULT + - word: CHARSET + - raw_comparison_operator: = + - word: utf8mb4 + - word: COLLATE + - raw_comparison_operator: = + - word: utf8mb4_unicode_ci + - semicolon: ; + - word: create + - word: table + - back_quote: '`tickets`' + - start_bracket: ( + - back_quote: '`id`' + - word: serial + - word: primary + - word: key + - comma: ',' + - back_quote: '`material_number`' + - word: varchar + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - word: default + - word: 'null' + - comma: ',' + - back_quote: '`material_name`' + - word: varchar + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - word: default + - word: 'null' + - comma: ',' + - back_quote: '`date_created`' + - word: date + - word: not + - word: 'null' + - word: default + - start_bracket: ( + - word: current_date + - end_bracket: ) + - comma: ',' + - back_quote: '`date_closed`' + - word: date + - word: default + - word: 'null' + - end_bracket: ) + - semicolon: ; + - word: create + - word: table + - word: _ + - start_bracket: ( + - word: a + - word: int + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: TABLE + - word: foo + - word: SELECT + - star: '*' + - word: FROM + - word: bar + - semicolon: ; + - word: CREATE + - word: TEMPORARY + - word: TABLE + - word: tbl_name + - start_bracket: ( + - word: id + - word: INT + - word: PRIMARY + - word: KEY + - word: AUTO_INCREMENT + - comma: ',' + - word: col + - word: VARCHAR + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - word: DEFAULT + - single_quote: '''''' + - word: NOT + - word: 'NULL' + - comma: ',' + - word: INDEX + - start_bracket: ( + - word: col + - end_bracket: ) + - end_bracket: ) + - word: AS + - word: SELECT + - word: id + - comma: ',' + - word: col + - word: FROM + - word: table_name + - semicolon: ; + - word: CREATE + - word: TEMPORARY + - word: TABLE + - word: tbl_name + - start_bracket: ( + - word: id + - word: INT + - word: PRIMARY + - word: KEY + - word: AUTO_INCREMENT + - comma: ',' + - word: col + - word: VARCHAR + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - word: DEFAULT + - single_quote: '''''' + - word: NOT + - word: 'NULL' + - comma: ',' + - word: INDEX + - start_bracket: ( + - word: col + - end_bracket: ) + - end_bracket: ) + - word: SELECT + - word: id + - comma: ',' + - word: col + - word: FROM + - word: table_name + - semicolon: ; + - word: CREATE + - word: TEMPORARY + - word: TABLE + - word: tbl_name + - start_bracket: ( + - word: INDEX + - start_bracket: ( + - word: col + - end_bracket: ) + - end_bracket: ) + - word: AS + - word: SELECT + - word: id + - comma: ',' + - word: col + - word: FROM + - word: table_name + - semicolon: ; + - word: CREATE + - word: TEMPORARY + - word: TABLE + - word: tbl_name + - start_bracket: ( + - word: INDEX + - start_bracket: ( + - word: col + - end_bracket: ) + - end_bracket: ) + - word: SELECT + - word: id + - comma: ',' + - word: col + - word: FROM + - word: table_name + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_column_charset.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_column_charset.sql new file mode 100644 index 000000000..dcb584410 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_column_charset.sql @@ -0,0 +1,6 @@ +CREATE TABLE t1 +( + col1 VARCHAR(5) + CHARACTER SET latin1 + COLLATE latin1_german1_ci +); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_column_charset.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_column_charset.yml new file mode 100644 index 000000000..e882f9885 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_column_charset.yml @@ -0,0 +1,18 @@ +file: +- unparsable: + - word: CREATE + - word: TABLE + - word: t1 + - start_bracket: ( + - word: col1 + - word: VARCHAR + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - word: CHARACTER + - word: SET + - word: latin1 + - word: COLLATE + - word: latin1_german1_ci + - end_bracket: ) + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_constraint_unique.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_constraint_unique.sql new file mode 100644 index 000000000..357b893c9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_constraint_unique.sql @@ -0,0 +1,9 @@ +CREATE TABLE a( + a INT NOT NULL, + UNIQUE (a), + UNIQUE idx_c(a), + UNIQUE KEY (a), + UNIQUE KEY idx_a(a), + UNIQUE INDEX (a), + UNIQUE INDEX idx_b(a) +) diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_constraint_unique.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_constraint_unique.yml new file mode 100644 index 000000000..ec8f15ee8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_constraint_unique.yml @@ -0,0 +1,48 @@ +file: +- unparsable: + - word: CREATE + - word: TABLE + - word: a + - start_bracket: ( + - word: a + - word: INT + - word: NOT + - word: 'NULL' + - comma: ',' + - word: UNIQUE + - start_bracket: ( + - word: a + - end_bracket: ) + - comma: ',' + - word: UNIQUE + - word: idx_c + - start_bracket: ( + - word: a + - end_bracket: ) + - comma: ',' + - word: UNIQUE + - word: KEY + - start_bracket: ( + - word: a + - end_bracket: ) + - comma: ',' + - word: UNIQUE + - word: KEY + - word: idx_a + - start_bracket: ( + - word: a + - end_bracket: ) + - comma: ',' + - word: UNIQUE + - word: INDEX + - start_bracket: ( + - word: a + - end_bracket: ) + - comma: ',' + - word: UNIQUE + - word: INDEX + - word: idx_b + - start_bracket: ( + - word: a + - end_bracket: ) + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_datetime.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_datetime.sql new file mode 100644 index 000000000..ee5ed35b0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_datetime.sql @@ -0,0 +1,25 @@ +CREATE TABLE `foo` ( + created_date DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + ts1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + dt1 DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + ts2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + dt2 DATETIME DEFAULT CURRENT_TIMESTAMP, + ts3 TIMESTAMP DEFAULT 0, + dt3 DATETIME DEFAULT 0, + ts4 TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP, + dt4 DATETIME DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP, + ts5 TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- default 0 + ts6 TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP, -- default NULL + dt5 DATETIME ON UPDATE CURRENT_TIMESTAMP, -- default NULL + dt6 DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP, -- default 0 + ts7 TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + ts8 TIMESTAMP NULL DEFAULT NULL, + ts9 TIMESTAMP NULL DEFAULT 0, + ts10 TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + ts11 TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP(), + ts12 TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00', + ts13 TIMESTAMP NULL DEFAULT NOW ON UPDATE NOW, + ts14 TIMESTAMP NULL DEFAULT NOW() ON UPDATE NOW(), + ts15 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + ts16 TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP +) diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_datetime.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_datetime.yml new file mode 100644 index 000000000..53a22019e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_datetime.yml @@ -0,0 +1,182 @@ +file: +- unparsable: + - word: CREATE + - word: TABLE + - back_quote: '`foo`' + - start_bracket: ( + - word: created_date + - word: DATETIME + - word: DEFAULT + - word: CURRENT_TIMESTAMP + - word: NOT + - word: 'NULL' + - comma: ',' + - word: ts1 + - word: TIMESTAMP + - word: DEFAULT + - word: CURRENT_TIMESTAMP + - word: ON + - word: UPDATE + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: dt1 + - word: DATETIME + - word: DEFAULT + - word: CURRENT_TIMESTAMP + - word: ON + - word: UPDATE + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: ts2 + - word: TIMESTAMP + - word: DEFAULT + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: dt2 + - word: DATETIME + - word: DEFAULT + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: ts3 + - word: TIMESTAMP + - word: DEFAULT + - numeric_literal: '0' + - comma: ',' + - word: dt3 + - word: DATETIME + - word: DEFAULT + - numeric_literal: '0' + - comma: ',' + - word: ts4 + - word: TIMESTAMP + - word: DEFAULT + - numeric_literal: '0' + - word: ON + - word: UPDATE + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: dt4 + - word: DATETIME + - word: DEFAULT + - numeric_literal: '0' + - word: ON + - word: UPDATE + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: ts5 + - word: TIMESTAMP + - word: ON + - word: UPDATE + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: ts6 + - word: TIMESTAMP + - word: 'NULL' + - word: ON + - word: UPDATE + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: dt5 + - word: DATETIME + - word: ON + - word: UPDATE + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: dt6 + - word: DATETIME + - word: NOT + - word: 'NULL' + - word: ON + - word: UPDATE + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: ts7 + - word: TIMESTAMP + - start_bracket: ( + - numeric_literal: '6' + - end_bracket: ) + - word: DEFAULT + - word: CURRENT_TIMESTAMP + - start_bracket: ( + - numeric_literal: '6' + - end_bracket: ) + - word: ON + - word: UPDATE + - word: CURRENT_TIMESTAMP + - start_bracket: ( + - numeric_literal: '6' + - end_bracket: ) + - comma: ',' + - word: ts8 + - word: TIMESTAMP + - word: 'NULL' + - word: DEFAULT + - word: 'NULL' + - comma: ',' + - word: ts9 + - word: TIMESTAMP + - word: 'NULL' + - word: DEFAULT + - numeric_literal: '0' + - comma: ',' + - word: ts10 + - word: TIMESTAMP + - word: 'NULL' + - word: DEFAULT + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: ts11 + - word: TIMESTAMP + - word: 'NULL' + - word: DEFAULT + - word: CURRENT_TIMESTAMP + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - word: ts12 + - word: TIMESTAMP + - word: 'NULL' + - word: DEFAULT + - single_quote: '''0000-00-00 00:00:00''' + - comma: ',' + - word: ts13 + - word: TIMESTAMP + - word: 'NULL' + - word: DEFAULT + - word: NOW + - word: ON + - word: UPDATE + - word: NOW + - comma: ',' + - word: ts14 + - word: TIMESTAMP + - word: 'NULL' + - word: DEFAULT + - word: NOW + - start_bracket: ( + - end_bracket: ) + - word: ON + - word: UPDATE + - word: NOW + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - word: ts15 + - word: TIMESTAMP + - word: NOT + - word: 'NULL' + - word: DEFAULT + - word: CURRENT_TIMESTAMP + - word: ON + - word: UPDATE + - word: CURRENT_TIMESTAMP + - comma: ',' + - word: ts16 + - word: TIMESTAMP + - word: 'NULL' + - word: DEFAULT + - word: 'NULL' + - word: ON + - word: UPDATE + - word: CURRENT_TIMESTAMP + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_equals_optional.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_equals_optional.sql new file mode 100644 index 000000000..d863f0146 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_equals_optional.sql @@ -0,0 +1,3 @@ +CREATE TABLE a ( + id INT +) COLLATE utf8_general_ci; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_equals_optional.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_equals_optional.yml new file mode 100644 index 000000000..bddac6c36 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_equals_optional.yml @@ -0,0 +1,17 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: a + - bracketed: + - start_bracket: ( + - naked_identifier: id + - data_type: + - data_type_identifier: INT + - end_bracket: ) +- file: + - word: COLLATE + - word: utf8_general_ci + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_generated_column.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_generated_column.sql new file mode 100644 index 000000000..d06506ab7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_generated_column.sql @@ -0,0 +1,17 @@ +CREATE TABLE t1 ( + a INT, + b INT, + c TEXT, + d INT GENERATED ALWAYS AS (a*abs(b)) VIRTUAL, + e TEXT GENERATED ALWAYS AS (substr(c,b,b+1)) STORED, + PRIMARY KEY (a) +); + +CREATE TABLE t1 ( + a INT, + b INT, + c TEXT, + d INT AS (a*abs(b)), + e TEXT AS (substr(c,b,b+1)) STORED COMMENT 'foo', + PRIMARY KEY (a) +); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_generated_column.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_generated_column.yml new file mode 100644 index 000000000..ba0080c55 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_generated_column.yml @@ -0,0 +1,107 @@ +file: +- unparsable: + - word: CREATE + - word: TABLE + - word: t1 + - start_bracket: ( + - word: a + - word: INT + - comma: ',' + - word: b + - word: INT + - comma: ',' + - word: c + - word: TEXT + - comma: ',' + - word: d + - word: INT + - word: GENERATED + - word: ALWAYS + - word: AS + - start_bracket: ( + - word: a + - star: '*' + - word: abs + - start_bracket: ( + - word: b + - end_bracket: ) + - end_bracket: ) + - word: VIRTUAL + - comma: ',' + - word: e + - word: TEXT + - word: GENERATED + - word: ALWAYS + - word: AS + - start_bracket: ( + - word: substr + - start_bracket: ( + - word: c + - comma: ',' + - word: b + - comma: ',' + - word: b + - plus: + + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - word: STORED + - comma: ',' + - word: PRIMARY + - word: KEY + - start_bracket: ( + - word: a + - end_bracket: ) + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: TABLE + - word: t1 + - start_bracket: ( + - word: a + - word: INT + - comma: ',' + - word: b + - word: INT + - comma: ',' + - word: c + - word: TEXT + - comma: ',' + - word: d + - word: INT + - word: AS + - start_bracket: ( + - word: a + - star: '*' + - word: abs + - start_bracket: ( + - word: b + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - word: e + - word: TEXT + - word: AS + - start_bracket: ( + - word: substr + - start_bracket: ( + - word: c + - comma: ',' + - word: b + - comma: ',' + - word: b + - plus: + + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - word: STORED + - word: COMMENT + - single_quote: '''foo''' + - comma: ',' + - word: PRIMARY + - word: KEY + - start_bracket: ( + - word: a + - end_bracket: ) + - end_bracket: ) + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_index.sql new file mode 100644 index 000000000..d26bd1e7f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_index.sql @@ -0,0 +1,12 @@ +CREATE TABLE foo ( + id INT UNSIGNED AUTO_INCREMENT NOT NULL, + a TEXT(500), + b INT, + c INT, + PRIMARY KEY (id) COMMENT 'primary key (id)', + FULLTEXT `idx_a` (a) COMMENT 'index (a)', + INDEX `idx_prefix_a` (a(20)), + INDEX `idx_b` (b) COMMENT 'index (b)', + INDEX `idx_desc_b` (b DESC), + INDEX `idx_asc_c` (c ASC) +) ENGINE=InnoDB; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_index.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_index.yml new file mode 100644 index 000000000..86d934f4d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_index.yml @@ -0,0 +1,76 @@ +file: +- unparsable: + - word: CREATE + - word: TABLE + - word: foo + - start_bracket: ( + - word: id + - word: INT + - word: UNSIGNED + - word: AUTO_INCREMENT + - word: NOT + - word: 'NULL' + - comma: ',' + - word: a + - word: TEXT + - start_bracket: ( + - numeric_literal: '500' + - end_bracket: ) + - comma: ',' + - word: b + - word: INT + - comma: ',' + - word: c + - word: INT + - comma: ',' + - word: PRIMARY + - word: KEY + - start_bracket: ( + - word: id + - end_bracket: ) + - word: COMMENT + - single_quote: '''primary key (id)''' + - comma: ',' + - word: FULLTEXT + - back_quote: '`idx_a`' + - start_bracket: ( + - word: a + - end_bracket: ) + - word: COMMENT + - single_quote: '''index (a)''' + - comma: ',' + - word: INDEX + - back_quote: '`idx_prefix_a`' + - start_bracket: ( + - word: a + - start_bracket: ( + - numeric_literal: '20' + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - word: INDEX + - back_quote: '`idx_b`' + - start_bracket: ( + - word: b + - end_bracket: ) + - word: COMMENT + - single_quote: '''index (b)''' + - comma: ',' + - word: INDEX + - back_quote: '`idx_desc_b`' + - start_bracket: ( + - word: b + - word: DESC + - end_bracket: ) + - comma: ',' + - word: INDEX + - back_quote: '`idx_asc_c`' + - start_bracket: ( + - word: c + - word: ASC + - end_bracket: ) + - end_bracket: ) + - word: ENGINE + - raw_comparison_operator: = + - word: InnoDB + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_null_position.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_null_position.sql new file mode 100644 index 000000000..6dc26b41e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_null_position.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS db_name.table_name +( + updated_at1 timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP, + updated_at2 timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, + updated_at3 timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP not null, + updated_at4 timestamp +); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_null_position.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_null_position.yml new file mode 100644 index 000000000..90cc2839f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_null_position.yml @@ -0,0 +1,48 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: db_name + - dot: . + - naked_identifier: table_name + - bracketed: + - start_bracket: ( + - naked_identifier: updated_at1 + - keyword: timestamp + - keyword: default + - keyword: CURRENT_TIMESTAMP + - keyword: not + - keyword: 'null' + - keyword: on + - keyword: update + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - naked_identifier: updated_at2 + - keyword: timestamp + - keyword: not + - keyword: 'null' + - keyword: default + - keyword: CURRENT_TIMESTAMP + - keyword: on + - keyword: update + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - naked_identifier: updated_at3 + - keyword: timestamp + - keyword: default + - keyword: CURRENT_TIMESTAMP + - keyword: on + - keyword: update + - keyword: CURRENT_TIMESTAMP + - keyword: not + - keyword: 'null' + - comma: ',' + - naked_identifier: updated_at4 + - keyword: timestamp + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_primary_foreign_keys.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_primary_foreign_keys.sql new file mode 100644 index 000000000..42eef540a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_primary_foreign_keys.sql @@ -0,0 +1,49 @@ +CREATE TABLE parent ( + id INT NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE child ( + id INT, + parent_id INT, + INDEX par_ind (parent_id), + FOREIGN KEY (parent_id) + REFERENCES parent(id) + ON DELETE CASCADE +); + +CREATE TABLE product ( + category INT NOT NULL, id INT NOT NULL, + price DECIMAL, + PRIMARY KEY(category, id) +); + +CREATE TABLE customer ( + id INT NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE product_order ( + product_category INT NOT NULL, + product_id INT NOT NULL, + customer_id INT NOT NULL, + + PRIMARY KEY(no), + -- INDEX (product_category, product_id), + -- INDEX (customer_id), + + FOREIGN KEY (product_category, product_id) + REFERENCES product(category, id) + ON UPDATE CASCADE ON DELETE RESTRICT, + + FOREIGN KEY (customer_id) + REFERENCES customer(id) +); + +CREATE TABLE source_tag_assoc ( + source_id INT UNSIGNED NOT NULL, + tag_id INT UNSIGNED NOT NULL, + PRIMARY KEY (source_id, tag_id), + FOREIGN KEY (source_id) REFERENCES source (id) ON DELETE CASCADE, + FOREIGN KEY (tag_id) REFERENCES source_tag (id) ON DELETE CASCADE +); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_primary_foreign_keys.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_primary_foreign_keys.yml new file mode 100644 index 000000000..fb20b02cc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_primary_foreign_keys.yml @@ -0,0 +1,211 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: parent + - bracketed: + - start_bracket: ( + - naked_identifier: id + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- file: + - word: CREATE + - word: TABLE + - word: child + - start_bracket: ( + - word: id + - word: INT + - comma: ',' + - word: parent_id + - word: INT + - comma: ',' + - word: INDEX + - word: par_ind + - start_bracket: ( + - word: parent_id + - end_bracket: ) + - comma: ',' + - word: FOREIGN + - word: KEY + - start_bracket: ( + - word: parent_id + - end_bracket: ) + - word: REFERENCES + - word: parent + - start_bracket: ( + - word: id + - end_bracket: ) + - word: ON + - word: DELETE + - word: CASCADE + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: TABLE + - word: product + - start_bracket: ( + - word: category + - word: INT + - word: NOT + - word: 'NULL' + - comma: ',' + - word: id + - word: INT + - word: NOT + - word: 'NULL' + - comma: ',' + - word: price + - word: DECIMAL + - comma: ',' + - word: PRIMARY + - word: KEY + - start_bracket: ( + - word: category + - comma: ',' + - word: id + - end_bracket: ) + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: TABLE + - word: customer + - start_bracket: ( + - word: id + - word: INT + - word: NOT + - word: 'NULL' + - comma: ',' + - word: PRIMARY + - word: KEY + - start_bracket: ( + - word: id + - end_bracket: ) + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: TABLE + - word: product_order + - start_bracket: ( + - word: product_category + - word: INT + - word: NOT + - word: 'NULL' + - comma: ',' + - word: product_id + - word: INT + - word: NOT + - word: 'NULL' + - comma: ',' + - word: customer_id + - word: INT + - word: NOT + - word: 'NULL' + - comma: ',' + - word: PRIMARY + - word: KEY + - start_bracket: ( + - word: no + - end_bracket: ) + - comma: ',' + - word: FOREIGN + - word: KEY + - start_bracket: ( + - word: product_category + - comma: ',' + - word: product_id + - end_bracket: ) + - word: REFERENCES + - word: product + - start_bracket: ( + - word: category + - comma: ',' + - word: id + - end_bracket: ) + - word: ON + - word: UPDATE + - word: CASCADE + - word: ON + - word: DELETE + - word: RESTRICT + - comma: ',' + - word: FOREIGN + - word: KEY + - start_bracket: ( + - word: customer_id + - end_bracket: ) + - word: REFERENCES + - word: customer + - start_bracket: ( + - word: id + - end_bracket: ) + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: TABLE + - word: source_tag_assoc + - start_bracket: ( + - word: source_id + - word: INT + - word: UNSIGNED + - word: NOT + - word: 'NULL' + - comma: ',' + - word: tag_id + - word: INT + - word: UNSIGNED + - word: NOT + - word: 'NULL' + - comma: ',' + - word: PRIMARY + - word: KEY + - start_bracket: ( + - word: source_id + - comma: ',' + - word: tag_id + - end_bracket: ) + - comma: ',' + - word: FOREIGN + - word: KEY + - start_bracket: ( + - word: source_id + - end_bracket: ) + - word: REFERENCES + - word: source + - start_bracket: ( + - word: id + - end_bracket: ) + - word: ON + - word: DELETE + - word: CASCADE + - comma: ',' + - word: FOREIGN + - word: KEY + - start_bracket: ( + - word: tag_id + - end_bracket: ) + - word: REFERENCES + - word: source_tag + - start_bracket: ( + - word: id + - end_bracket: ) + - word: ON + - word: DELETE + - word: CASCADE + - end_bracket: ) + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_unique_key.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_unique_key.sql new file mode 100644 index 000000000..0ca8244df --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_unique_key.sql @@ -0,0 +1,3 @@ +create table a( + b int unique key +); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_unique_key.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_unique_key.yml new file mode 100644 index 000000000..af81cfc3a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_table_unique_key.yml @@ -0,0 +1,12 @@ +file: +- unparsable: + - word: create + - word: table + - word: a + - start_bracket: ( + - word: b + - word: int + - word: unique + - word: key + - end_bracket: ) + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_trigger.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_trigger.sql new file mode 100644 index 000000000..822af0379 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_trigger.sql @@ -0,0 +1,44 @@ +CREATE TRIGGER delete_members_after_transactions AFTER DELETE ON transactions +FOR EACH ROW DELETE FROM members WHERE username NOT IN +(SELECT UNIQUE(username) FROM transactions); + + + +CREATE TRIGGER some_trigger AFTER DELETE ON some_table +FOR EACH ROW +BEGIN + DELETE FROM some_table; + INSERT INTO some_table; +END; + + +CREATE TRIGGER ins_sum BEFORE INSERT ON account +FOR EACH ROW SET @sum = @sum + NEW.amount; + + +CREATE TRIGGER some_trigger AFTER DELETE ON some_table FOR EACH ROW DELETE FROM other_table; +CREATE TRIGGER some_trigger BEFORE DELETE ON some_table FOR EACH ROW DELETE FROM other_table; +CREATE TRIGGER some_trigger AFTER UPDATE ON some_table FOR EACH ROW DELETE FROM other_table; +CREATE TRIGGER some_trigger BEFORE UPDATE ON some_table FOR EACH ROW DELETE FROM other_table; +CREATE TRIGGER some_trigger AFTER INSERT ON some_table FOR EACH ROW DELETE FROM other_table; +CREATE TRIGGER some_trigger BEFORE INSERT ON some_table FOR EACH ROW DELETE FROM other_table; + +CREATE TRIGGER IF NOT EXISTS some_trigger AFTER DELETE ON some_table +FOR EACH ROW DELETE FROM other_table; + +CREATE TRIGGER some_trigger AFTER DELETE ON some_table FOR EACH ROW +FOLLOWS some_other_trigger +DELETE FROM other_table; +CREATE TRIGGER some_trigger AFTER DELETE ON some_table FOR EACH ROW +PRECEDES some_other_trigger +DELETE FROM other_table; + + +CREATE +DEFINER=`root`@`127.0.0.1` +TRIGGER ins_sum BEFORE INSERT ON account +FOR EACH ROW SET @sum = @sum + NEW.amount; +CREATE +DEFINER=CURRENT_USER +TRIGGER ins_sum BEFORE INSERT ON account +FOR EACH ROW SET @sum = @sum + NEW.amount; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_trigger.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_trigger.yml new file mode 100644 index 000000000..e080c9285 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_trigger.yml @@ -0,0 +1,65 @@ +file: +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: delete_members_after_transactions + - keyword: AFTER + - keyword: DELETE + - keyword: ON + - table_reference: + - naked_identifier: transactions + - keyword: FOR + - keyword: EACH + - keyword: ROW +- file: + - word: DELETE + - word: FROM + - word: members + - word: WHERE + - word: username + - word: NOT + - word: IN + - start_bracket: ( + - word: SELECT + - word: UNIQUE + - start_bracket: ( + - word: username + - end_bracket: ) + - word: FROM + - word: transactions + - end_bracket: ) + - semicolon: ; + - word: CREATE + - word: TRIGGER + - word: some_trigger + - word: AFTER + - word: DELETE + - word: ON + - word: some_table + - word: FOR + - word: EACH + - word: ROW + - word: BEGIN + - word: DELETE + - word: FROM + - word: some_table + - semicolon: ; + - word: INSERT + - word: INTO + - word: some_table + - semicolon: ; + - word: END + - semicolon: ; + - word: CREATE + - word: TRIGGER + - word: ins_sum + - word: BEFORE + - word: INSERT + - word: ON + - word: account + - word: FOR + - word: EACH + - word: ROW + - word: SET diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_user.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_user.sql new file mode 100644 index 000000000..134eed9e3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_user.sql @@ -0,0 +1,74 @@ +CREATE USER jeffrey; +CREATE USER IF NOT EXISTS jeffrey; +CREATE USER 'prj_svc' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS'; +CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'password'; +CREATE USER "jeffrey"@"localhost" IDENTIFIED BY "password"; +CREATE USER `jeffrey`@`localhost` IDENTIFIED BY "password"; +CREATE USER 'jeffrey'@'localhost' + IDENTIFIED BY 'new_password' PASSWORD EXPIRE; +CREATE USER 'jeffrey'@'localhost' + IDENTIFIED WITH caching_sha2_password BY 'new_password' + PASSWORD EXPIRE INTERVAL 180 DAY + FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2; +CREATE USER + 'jeffrey'@'localhost' IDENTIFIED WITH mysql_native_password + BY 'new_password1', + 'jeanne'@'localhost' IDENTIFIED WITH caching_sha2_password + BY 'new_password2' + REQUIRE X509 WITH MAX_QUERIES_PER_HOUR 60 + PASSWORD HISTORY 5 + ACCOUNT LOCK; +CREATE USER 'jeffrey'@'localhost' + IDENTIFIED WITH mysql_native_password BY 'password'; +CREATE USER 'u1'@'localhost' + IDENTIFIED WITH caching_sha2_password + BY 'sha2_password' + AND IDENTIFIED WITH authentication_ldap_sasl + AS 'uid=u1_ldap,ou=People,dc=example,dc=com'; +CREATE USER 'u1'@'localhost' + IDENTIFIED WITH caching_sha2_password + BY 'sha2_password' + AND IDENTIFIED WITH authentication_ldap_sasl + AS 'uid=u1_ldap,ou=People,dc=example,dc=com' + AND IDENTIFIED WITH authentication_fido; +CREATE USER user + IDENTIFIED WITH authentication_fido + INITIAL AUTHENTICATION IDENTIFIED BY RANDOM PASSWORD; +CREATE USER 'joe'@'10.0.0.1' DEFAULT ROLE administrator, developer; +CREATE USER 'jeffrey'@'localhost' REQUIRE NONE; +CREATE USER 'jeffrey'@'localhost' REQUIRE SSL; +CREATE USER 'jeffrey'@'localhost' REQUIRE X509; +CREATE USER 'jeffrey'@'localhost' + REQUIRE ISSUER '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL/CN=CA/emailAddress=ca@example.com'; +CREATE USER 'jeffrey'@'localhost' + REQUIRE SUBJECT '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL demo client certificate/ + CN=client/emailAddress=client@example.com'; +CREATE USER 'jeffrey'@'localhost' + REQUIRE CIPHER 'EDH-RSA-DES-CBC3-SHA'; +CREATE USER 'jeffrey'@'localhost' + REQUIRE SUBJECT '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL demo client certificate/ + CN=client/emailAddress=client@example.com' + AND ISSUER '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL/CN=CA/emailAddress=ca@example.com' + AND CIPHER 'EDH-RSA-DES-CBC3-SHA'; +CREATE USER 'jeffrey'@'localhost' + WITH MAX_QUERIES_PER_HOUR 500 MAX_UPDATES_PER_HOUR 100; +CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE; +CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE DEFAULT; +CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER; +CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE INTERVAL 180 DAY; +CREATE USER 'jeffrey'@'localhost' PASSWORD HISTORY DEFAULT; +CREATE USER 'jeffrey'@'localhost' PASSWORD HISTORY 6; +CREATE USER 'jeffrey'@'localhost' PASSWORD REUSE INTERVAL DEFAULT; +CREATE USER 'jeffrey'@'localhost' PASSWORD REUSE INTERVAL 360 DAY; +CREATE USER 'jeffrey'@'localhost' PASSWORD REQUIRE CURRENT; +CREATE USER 'jeffrey'@'localhost' PASSWORD REQUIRE CURRENT OPTIONAL; +CREATE USER 'jeffrey'@'localhost' PASSWORD REQUIRE CURRENT DEFAULT; +CREATE USER 'jeffrey'@'localhost' + FAILED_LOGIN_ATTEMPTS 4 PASSWORD_LOCK_TIME 2; +CREATE USER 'jon'@'localhost' COMMENT 'Some information about Jon'; +CREATE USER 'jim'@'localhost' + ATTRIBUTE '{"fname": "James", "lname": "Scott", "phone": "123-456-7890"}'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_user.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_user.yml new file mode 100644 index 000000000..1a3fc5fce --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_user.yml @@ -0,0 +1,29 @@ +file: +- statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: jeffrey +- statement_terminator: ; +- statement: + - keyword: CREATE + - keyword: USER + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - role_reference: + - naked_identifier: jeffrey +- statement_terminator: ; +- file: + - word: CREATE + - word: USER + - single_quote: '''prj_svc''' + - word: IDENTIFIED + - word: WITH + - word: AWSAuthenticationPlugin + - word: AS + - single_quote: '''RDS''' + - semicolon: ; + - word: CREATE + - word: USER + - single_quote: '''jeffrey''' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_view.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/create_view.sql new file mode 100644 index 000000000..c82144e77 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_view.sql @@ -0,0 +1,24 @@ +CREATE VIEW v1 (c,d) AS + SELECT a,b FROM t1; + +CREATE OR REPLACE VIEW v1 (c,d,e,f) AS + SELECT a,b, a IN (SELECT a+2 FROM t1), a = all (SELECT a FROM t1) FROM t1; + +CREATE VIEW v2 AS SELECT a FROM t1 WITH CASCADED CHECK OPTION; + +CREATE VIEW v2 AS (SELECT a FROM t1) WITH CASCADED CHECK OPTION; + +CREATE VIEW v2 AS + SELECT 1 UNION SELECT 2; + + + +CREATE VIEW vw_test AS + WITH testing_cte as ( + SELECT + a + , b + FROM t1 + ) + SELECT a, b from testing_cte +; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/create_view.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/create_view.yml new file mode 100644 index 000000000..f1ac86835 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/create_view.yml @@ -0,0 +1,214 @@ +file: +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c + - comma: ',' + - column_reference: + - naked_identifier: d + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c + - comma: ',' + - column_reference: + - naked_identifier: d + - comma: ',' + - column_reference: + - naked_identifier: e + - comma: ',' + - column_reference: + - naked_identifier: f + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: a + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: + + - numeric_literal: '2' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - end_bracket: ) + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: all + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - unparsable: + - word: WITH + - word: CASCADED + - word: CHECK + - word: OPTION +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - end_bracket: ) +- file: + - word: WITH + - word: CASCADED + - word: CHECK + - word: OPTION + - semicolon: ; + - word: CREATE + - word: VIEW + - word: v2 + - word: AS + - word: SELECT + - numeric_literal: '1' + - word: UNION + - word: SELECT + - numeric_literal: '2' + - semicolon: ; + - word: CREATE + - word: VIEW + - word: vw_test + - word: AS + - word: WITH + - word: testing_cte + - word: as + - start_bracket: ( + - word: SELECT + - word: a + - comma: ',' + - word: b + - word: FROM + - word: t1 + - end_bracket: ) + - word: SELECT + - word: a + - comma: ',' + - word: b + - word: from + - word: testing_cte + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/deallocate_prepare.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/deallocate_prepare.sql new file mode 100644 index 000000000..993de88a2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/deallocate_prepare.sql @@ -0,0 +1 @@ +DEALLOCATE PREPARE dynam; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/deallocate_prepare.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/deallocate_prepare.yml new file mode 100644 index 000000000..a2eb1d4cc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/deallocate_prepare.yml @@ -0,0 +1,6 @@ +file: +- statement: + - keyword: DEALLOCATE + - keyword: PREPARE + - naked_identifier: dynam +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_condition.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_condition.sql new file mode 100644 index 000000000..8a77f2096 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_condition.sql @@ -0,0 +1 @@ +DECLARE random_condition_name CONDITION FOR 1051; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_condition.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_condition.yml new file mode 100644 index 000000000..4444eaaf4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_condition.yml @@ -0,0 +1,8 @@ +file: +- statement: + - keyword: DECLARE + - naked_identifier: random_condition_name + - keyword: CONDITION + - keyword: FOR + - numeric_literal: '1051' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_continue_handler_sqlexception.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_continue_handler_sqlexception.sql new file mode 100644 index 000000000..435b03cf6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_continue_handler_sqlexception.sql @@ -0,0 +1,4 @@ +DECLARE continue handler for sqlexception +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_continue_handler_sqlexception.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_continue_handler_sqlexception.yml new file mode 100644 index 000000000..23264c0c4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_continue_handler_sqlexception.yml @@ -0,0 +1,16 @@ +file: +- statement: + - keyword: DECLARE + - keyword: continue + - keyword: handler + - keyword: for + - keyword: sqlexception + - statement: + - transaction_statement: + - keyword: begin +- file: + - word: select + - numeric_literal: '1' + - semicolon: ; + - word: end + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_cursor.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_cursor.sql new file mode 100644 index 000000000..579e37803 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_cursor.sql @@ -0,0 +1 @@ +DECLARE test CURSOR FOR SELECT 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_cursor.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_cursor.yml new file mode 100644 index 000000000..be1fb081b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_cursor.yml @@ -0,0 +1,13 @@ +file: +- statement: + - keyword: DECLARE + - naked_identifier: test + - keyword: CURSOR + - keyword: FOR + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_numeric.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_numeric.sql new file mode 100644 index 000000000..6a57eee3d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_numeric.sql @@ -0,0 +1 @@ +DECLARE abc int default 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_numeric.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_numeric.yml new file mode 100644 index 000000000..c5afcbc0e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_numeric.yml @@ -0,0 +1,9 @@ +file: +- statement: + - keyword: DECLARE + - variable: abc + - data_type: + - data_type_identifier: int + - keyword: default + - numeric_literal: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_quotedliteral.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_quotedliteral.sql new file mode 100644 index 000000000..13cb3cb80 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_quotedliteral.sql @@ -0,0 +1 @@ +DECLARE abc longtext default 'test'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_quotedliteral.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_quotedliteral.yml new file mode 100644 index 000000000..2d781cd46 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_default_quotedliteral.yml @@ -0,0 +1,9 @@ +file: +- statement: + - keyword: DECLARE + - variable: abc + - data_type: + - data_type_identifier: longtext + - keyword: default + - quoted_literal: '''test''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_exit_handler_sqlexception.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_exit_handler_sqlexception.sql new file mode 100644 index 000000000..fa6f22dae --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_exit_handler_sqlexception.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for sqlexception +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_exit_handler_sqlexception.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_exit_handler_sqlexception.yml new file mode 100644 index 000000000..b6b41dbfe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_exit_handler_sqlexception.yml @@ -0,0 +1,16 @@ +file: +- statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - keyword: sqlexception + - statement: + - transaction_statement: + - keyword: begin +- file: + - word: select + - numeric_literal: '1' + - semicolon: ; + - word: end + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_local_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_local_variable.sql new file mode 100644 index 000000000..e0fd0b204 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_local_variable.sql @@ -0,0 +1 @@ +DECLARE abc int; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_local_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_local_variable.yml new file mode 100644 index 000000000..4f77d8a20 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_local_variable.yml @@ -0,0 +1,7 @@ +file: +- statement: + - keyword: DECLARE + - variable: abc + - data_type: + - data_type_identifier: int +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_undo_handler_sqlexception.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_undo_handler_sqlexception.sql new file mode 100644 index 000000000..fcfdec27f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_undo_handler_sqlexception.sql @@ -0,0 +1,4 @@ +DECLARE undo handler for sqlexception +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/declare_undo_handler_sqlexception.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_undo_handler_sqlexception.yml new file mode 100644 index 000000000..773d4750a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/declare_undo_handler_sqlexception.yml @@ -0,0 +1,16 @@ +file: +- statement: + - keyword: DECLARE + - keyword: undo + - keyword: handler + - keyword: for + - keyword: sqlexception + - statement: + - transaction_statement: + - keyword: begin +- file: + - word: select + - numeric_literal: '1' + - semicolon: ; + - word: end + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/delete_multitable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/delete_multitable.sql new file mode 100644 index 000000000..e95fe9f10 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/delete_multitable.sql @@ -0,0 +1,32 @@ +DELETE a FROM a JOIN b USING (id) WHERE b.name = 'example'; + +DELETE FROM somelog WHERE user = 'jcole' +ORDER BY timestamp_column LIMIT 1; + +DELETE LOW_PRIORITY QUICK IGNORE a FROM a JOIN b USING (id) WHERE b.name = 'example'; + +DELETE FROM a PARTITION (p) WHERE b.name = 'example'; + +-- Multiple-Table Syntax 1 +DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; + +DELETE LOW_PRIORITY QUICK IGNORE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; + +-- Multiple-Table Syntax 2 +DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; + +DELETE LOW_PRIORITY QUICK IGNORE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; + +DELETE a1, a2 FROM t1 AS a1 INNER JOIN t2 AS a2 +WHERE a1.id=a2.id; + +-- .* after table name +DELETE t1.*, t2.* FROM t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; + +DELETE FROM t1.*, t2.* USING t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/delete_multitable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/delete_multitable.yml new file mode 100644 index 000000000..e2de4f650 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/delete_multitable.yml @@ -0,0 +1,279 @@ +file: +- unparsable: + - word: DELETE + - word: a + - word: FROM + - word: a + - word: JOIN + - word: b + - word: USING + - start_bracket: ( + - word: id + - end_bracket: ) + - word: WHERE + - word: b + - dot: . + - word: name + - raw_comparison_operator: = + - single_quote: '''example''' + - semicolon: ; + - word: DELETE + - word: FROM + - word: somelog + - word: WHERE + - word: user + - raw_comparison_operator: = + - single_quote: '''jcole''' + - word: ORDER + - word: BY + - word: timestamp_column + - word: LIMIT + - numeric_literal: '1' + - semicolon: ; + - word: DELETE + - word: LOW_PRIORITY + - word: QUICK + - word: IGNORE + - word: a + - word: FROM + - word: a + - word: JOIN + - word: b + - word: USING + - start_bracket: ( + - word: id + - end_bracket: ) + - word: WHERE + - word: b + - dot: . + - word: name + - raw_comparison_operator: = + - single_quote: '''example''' + - semicolon: ; + - word: DELETE + - word: FROM + - word: a + - word: PARTITION + - start_bracket: ( + - word: p + - end_bracket: ) + - word: WHERE + - word: b + - dot: . + - word: name + - raw_comparison_operator: = + - single_quote: '''example''' + - semicolon: ; + - word: DELETE + - word: t1 + - comma: ',' + - word: t2 + - word: FROM + - word: t1 + - word: INNER + - word: JOIN + - word: t2 + - word: INNER + - word: JOIN + - word: t3 + - word: WHERE + - word: t1 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t2 + - dot: . + - word: id + - word: AND + - word: t2 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t3 + - dot: . + - word: id + - semicolon: ; + - word: DELETE + - word: LOW_PRIORITY + - word: QUICK + - word: IGNORE + - word: t1 + - comma: ',' + - word: t2 + - word: FROM + - word: t1 + - word: INNER + - word: JOIN + - word: t2 + - word: INNER + - word: JOIN + - word: t3 + - word: WHERE + - word: t1 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t2 + - dot: . + - word: id + - word: AND + - word: t2 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t3 + - dot: . + - word: id + - semicolon: ; + - word: DELETE + - word: FROM + - word: t1 + - comma: ',' + - word: t2 + - word: USING + - word: t1 + - word: INNER + - word: JOIN + - word: t2 + - word: INNER + - word: JOIN + - word: t3 + - word: WHERE + - word: t1 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t2 + - dot: . + - word: id + - word: AND + - word: t2 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t3 + - dot: . + - word: id + - semicolon: ; + - word: DELETE + - word: LOW_PRIORITY + - word: QUICK + - word: IGNORE + - word: FROM + - word: t1 + - comma: ',' + - word: t2 + - word: USING + - word: t1 + - word: INNER + - word: JOIN + - word: t2 + - word: INNER + - word: JOIN + - word: t3 + - word: WHERE + - word: t1 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t2 + - dot: . + - word: id + - word: AND + - word: t2 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t3 + - dot: . + - word: id + - semicolon: ; + - word: DELETE + - word: a1 + - comma: ',' + - word: a2 + - word: FROM + - word: t1 + - word: AS + - word: a1 + - word: INNER + - word: JOIN + - word: t2 + - word: AS + - word: a2 + - word: WHERE + - word: a1 + - dot: . + - word: id + - raw_comparison_operator: = + - word: a2 + - dot: . + - word: id + - semicolon: ; + - word: DELETE + - word: t1 + - dot: . + - star: '*' + - comma: ',' + - word: t2 + - dot: . + - star: '*' + - word: FROM + - word: t1 + - word: INNER + - word: JOIN + - word: t2 + - word: INNER + - word: JOIN + - word: t3 + - word: WHERE + - word: t1 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t2 + - dot: . + - word: id + - word: AND + - word: t2 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t3 + - dot: . + - word: id + - semicolon: ; + - word: DELETE + - word: FROM + - word: t1 + - dot: . + - star: '*' + - comma: ',' + - word: t2 + - dot: . + - star: '*' + - word: USING + - word: t1 + - word: INNER + - word: JOIN + - word: t2 + - word: INNER + - word: JOIN + - word: t3 + - word: WHERE + - word: t1 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t2 + - dot: . + - word: id + - word: AND + - word: t2 + - dot: . + - word: id + - raw_comparison_operator: = + - word: t3 + - dot: . + - word: id + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_function.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_function.sql new file mode 100644 index 000000000..e175ab683 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_function.sql @@ -0,0 +1,11 @@ +DELIMITER ~ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +LANGUAGE SQL +CONTAINS SQL +SQL SECURITY DEFINER +BEGIN +SELECT 1 + 2; +END~ +DELIMITER ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_function.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_function.yml new file mode 100644 index 000000000..4ae2fd6b5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_function.yml @@ -0,0 +1,32 @@ +file: +- statement: + - keyword: DELIMITER +- file: + - like_operator: '~' + - word: CREATE + - word: FUNCTION + - back_quote: '`add`' + - start_bracket: ( + - word: test + - word: int + - end_bracket: ) + - word: RETURNS + - word: longtext + - word: DETERMINISTIC + - word: LANGUAGE + - word: SQL + - word: CONTAINS + - word: SQL + - word: SQL + - word: SECURITY + - word: DEFINER + - word: BEGIN + - word: SELECT + - numeric_literal: '1' + - plus: + + - numeric_literal: '2' + - semicolon: ; + - word: END + - like_operator: '~' + - word: DELIMITER + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_procedure.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_procedure.sql new file mode 100644 index 000000000..1600b553d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_procedure.sql @@ -0,0 +1,10 @@ +DELIMITER ~ +CREATE PROCEDURE `testprocedure`(test int) +DETERMINISTIC +LANGUAGE SQL +CONTAINS SQL +SQL SECURITY DEFINER +BEGIN +SELECT 1 + 2; +END~ +DELIMITER ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_procedure.yml new file mode 100644 index 000000000..fc1ecf3b7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_procedure.yml @@ -0,0 +1,30 @@ +file: +- statement: + - keyword: DELIMITER +- file: + - like_operator: '~' + - word: CREATE + - word: PROCEDURE + - back_quote: '`testprocedure`' + - start_bracket: ( + - word: test + - word: int + - end_bracket: ) + - word: DETERMINISTIC + - word: LANGUAGE + - word: SQL + - word: CONTAINS + - word: SQL + - word: SQL + - word: SECURITY + - word: DEFINER + - word: BEGIN + - word: SELECT + - numeric_literal: '1' + - plus: + + - numeric_literal: '2' + - semicolon: ; + - word: END + - like_operator: '~' + - word: DELIMITER + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_select.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_select.sql new file mode 100644 index 000000000..065b19883 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_select.sql @@ -0,0 +1,3 @@ +DELIMITER ~ +SELECT 1~ +DELIMITER ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_select.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_select.yml new file mode 100644 index 000000000..3e1daa4de --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/delimiter_select.yml @@ -0,0 +1,10 @@ +file: +- statement: + - keyword: DELIMITER +- file: + - like_operator: '~' + - word: SELECT + - numeric_literal: '1' + - like_operator: '~' + - word: DELIMITER + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_function.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_function.sql new file mode 100644 index 000000000..2cce85c56 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_function.sql @@ -0,0 +1 @@ +DROP FUNCTION IF EXISTS `testfunction`; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_function.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_function.yml new file mode 100644 index 000000000..350224be6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_function.yml @@ -0,0 +1,8 @@ +file: +- unparsable: + - word: DROP + - word: FUNCTION + - word: IF + - word: EXISTS + - back_quote: '`testfunction`' + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index.sql new file mode 100644 index 000000000..4fbd32c00 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index.sql @@ -0,0 +1 @@ +DROP INDEX `test` ON `table1`.`foo`; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index.yml new file mode 100644 index 000000000..534a0d4e9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index.yml @@ -0,0 +1,10 @@ +file: +- unparsable: + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - dot: . + - back_quote: '`foo`' + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_algorithm.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_algorithm.sql new file mode 100644 index 000000000..d904c3776 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_algorithm.sql @@ -0,0 +1,6 @@ +DROP INDEX `test` ON `table1`.`foo` ALGORITHM = DEFAULT; +DROP INDEX `test` ON `table1`.`foo` ALGORITHM = INPLACE; +DROP INDEX `test` ON `table1`.`foo` ALGORITHM = COPY; +DROP INDEX `test` ON `table1`.`foo` ALGORITHM DEFAULT; +DROP INDEX `test` ON `table1`.`foo` ALGORITHM INPLACE; +DROP INDEX `test` ON `table1`.`foo` ALGORITHM COPY; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_algorithm.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_algorithm.yml new file mode 100644 index 000000000..15c89bb4b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_algorithm.yml @@ -0,0 +1,65 @@ +file: +- unparsable: + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - dot: . + - back_quote: '`foo`' + - word: ALGORITHM + - raw_comparison_operator: = + - word: DEFAULT + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - dot: . + - back_quote: '`foo`' + - word: ALGORITHM + - raw_comparison_operator: = + - word: INPLACE + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - dot: . + - back_quote: '`foo`' + - word: ALGORITHM + - raw_comparison_operator: = + - word: COPY + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - dot: . + - back_quote: '`foo`' + - word: ALGORITHM + - word: DEFAULT + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - dot: . + - back_quote: '`foo`' + - word: ALGORITHM + - word: INPLACE + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - dot: . + - back_quote: '`foo`' + - word: ALGORITHM + - word: COPY + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_lock.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_lock.sql new file mode 100644 index 000000000..90560f63a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_lock.sql @@ -0,0 +1,8 @@ +DROP INDEX `test` ON `table1` LOCK = DEFAULT; +DROP INDEX `test` ON `table1` LOCK = NONE; +DROP INDEX `test` ON `table1` LOCK = SHARED; +DROP INDEX `test` ON `table1` LOCK = EXCLUSIVE; +DROP INDEX `test` ON `table1` LOCK DEFAULT; +DROP INDEX `test` ON `table1` LOCK NONE; +DROP INDEX `test` ON `table1` LOCK SHARED; +DROP INDEX `test` ON `table1` LOCK EXCLUSIVE; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_lock.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_lock.yml new file mode 100644 index 000000000..89735a6dd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_index_with_lock.yml @@ -0,0 +1,70 @@ +file: +- unparsable: + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - word: LOCK + - raw_comparison_operator: = + - word: DEFAULT + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - word: LOCK + - raw_comparison_operator: = + - word: NONE + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - word: LOCK + - raw_comparison_operator: = + - word: SHARED + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - word: LOCK + - raw_comparison_operator: = + - word: EXCLUSIVE + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - word: LOCK + - word: DEFAULT + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - word: LOCK + - word: NONE + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - word: LOCK + - word: SHARED + - semicolon: ; + - word: DROP + - word: INDEX + - back_quote: '`test`' + - word: ON + - back_quote: '`table1`' + - word: LOCK + - word: EXCLUSIVE + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_prepare.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_prepare.sql new file mode 100644 index 000000000..7d8efd833 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_prepare.sql @@ -0,0 +1 @@ +DROP PREPARE dynam; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_prepare.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_prepare.yml new file mode 100644 index 000000000..98dc3d1e7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_prepare.yml @@ -0,0 +1,6 @@ +file: +- statement: + - keyword: DROP + - keyword: PREPARE + - naked_identifier: dynam +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_procedure.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_procedure.sql new file mode 100644 index 000000000..306457c77 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_procedure.sql @@ -0,0 +1 @@ +DROP PROCEDURE IF EXISTS `testprocedure`; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_procedure.yml new file mode 100644 index 000000000..10c49bcea --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_procedure.yml @@ -0,0 +1,8 @@ +file: +- unparsable: + - word: DROP + - word: PROCEDURE + - word: IF + - word: EXISTS + - back_quote: '`testprocedure`' + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_table.sql new file mode 100644 index 000000000..dfc89d132 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_table.sql @@ -0,0 +1,7 @@ +DROP TEMPORARY TABLE IF EXISTS t; + +DROP TEMPORARY TABLE IF EXISTS t, t2; + +DROP TABLE IF EXISTS t RESTRICT; + +DROP TABLE IF EXISTS t CASCADE; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_table.yml new file mode 100644 index 000000000..8fe3550a2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_table.yml @@ -0,0 +1,44 @@ +file: +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: TEMPORARY + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: t +- statement_terminator: ; +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: TEMPORARY + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: t + - comma: ',' + - table_reference: + - naked_identifier: t2 +- statement_terminator: ; +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: t + - keyword: RESTRICT +- statement_terminator: ; +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: t + - keyword: CASCADE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_trigger.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_trigger.sql new file mode 100644 index 000000000..6eedbd550 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_trigger.sql @@ -0,0 +1,5 @@ +DROP TRIGGER trigger_name; + +DROP TRIGGER schema_name.trigger_name; + +DROP TRIGGER IF EXISTS trigger_name; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/drop_trigger.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_trigger.yml new file mode 100644 index 000000000..af23a8147 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/drop_trigger.yml @@ -0,0 +1,26 @@ +file: +- statement: + - drop_trigger_statement: + - keyword: DROP + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: trigger_name +- statement_terminator: ; +- statement: + - drop_trigger_statement: + - keyword: DROP + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: schema_name + - dot: . + - naked_identifier: trigger_name +- statement_terminator: ; +- statement: + - drop_trigger_statement: + - keyword: DROP + - keyword: TRIGGER + - keyword: IF + - keyword: EXISTS + - trigger_reference: + - naked_identifier: trigger_name +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt.sql new file mode 100644 index 000000000..99f480d99 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt.sql @@ -0,0 +1 @@ +execute test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt.yml new file mode 100644 index 000000000..4b8345fd8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt.yml @@ -0,0 +1,5 @@ +file: +- statement: + - keyword: execute + - naked_identifier: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using.sql new file mode 100644 index 000000000..26256840c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using.sql @@ -0,0 +1 @@ +execute test using @test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using.yml new file mode 100644 index 000000000..637c6df92 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using.yml @@ -0,0 +1,6 @@ +file: +- statement: + - keyword: execute + - naked_identifier: test +- file: + - word: using diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using_multiple_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using_multiple_variable.sql new file mode 100644 index 000000000..b2cd9fb27 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using_multiple_variable.sql @@ -0,0 +1 @@ +execute test using @test, @test1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using_multiple_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using_multiple_variable.yml new file mode 100644 index 000000000..637c6df92 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/execute_prepared_stmt_using_multiple_variable.yml @@ -0,0 +1,6 @@ +file: +- statement: + - keyword: execute + - naked_identifier: test +- file: + - word: using diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/explain.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/explain.sql new file mode 100644 index 000000000..95b72eba3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/explain.sql @@ -0,0 +1,7 @@ +explain select 1; + +explain update tbl set foo = 1 where bar = 2; + +explain delete from tbl where foo = 1; + +explain insert into tbl (col1) values (123); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/explain.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/explain.yml new file mode 100644 index 000000000..5c08626d0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/explain.yml @@ -0,0 +1,74 @@ +file: +- statement: + - explain_statement: + - keyword: explain + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - explain_statement: + - keyword: explain + - keyword: update + - table_reference: + - naked_identifier: tbl + - set_clause_list: + - keyword: set + - set_clause: + - column_reference: + - naked_identifier: foo + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - where_clause: + - keyword: where + - expression: + - column_reference: + - naked_identifier: bar + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - explain_statement: + - keyword: explain + - delete_statement: + - keyword: delete + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl + - where_clause: + - keyword: where + - expression: + - column_reference: + - naked_identifier: foo + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - explain_statement: + - keyword: explain + - insert_statement: + - keyword: insert + - keyword: into + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - values_clause: + - keyword: values + - bracketed: + - start_bracket: ( + - numeric_literal: '123' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch.sql new file mode 100644 index 000000000..fb51c83ed --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch.sql @@ -0,0 +1 @@ +fetch curcursor into test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch.yml new file mode 100644 index 000000000..b33bf748c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch.yml @@ -0,0 +1,7 @@ +file: +- statement: + - keyword: fetch + - naked_identifier: curcursor + - keyword: into + - variable: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_from.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_from.sql new file mode 100644 index 000000000..25a2e382e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_from.sql @@ -0,0 +1 @@ +fetch from curcursor into test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_from.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_from.yml new file mode 100644 index 000000000..3830b9b57 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_from.yml @@ -0,0 +1,8 @@ +file: +- statement: + - keyword: fetch + - keyword: from + - naked_identifier: curcursor + - keyword: into + - variable: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_multiple.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_multiple.sql new file mode 100644 index 000000000..66dc7b9f4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_multiple.sql @@ -0,0 +1 @@ +fetch curcursor into test, test2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_multiple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_multiple.yml new file mode 100644 index 000000000..453646d5b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_multiple.yml @@ -0,0 +1,9 @@ +file: +- statement: + - keyword: fetch + - naked_identifier: curcursor + - keyword: into + - variable: test + - comma: ',' + - variable: test2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_next_from.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_next_from.sql new file mode 100644 index 000000000..0a0c5b8a3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_next_from.sql @@ -0,0 +1 @@ +fetch next from curcursor into test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_next_from.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_next_from.yml new file mode 100644 index 000000000..315cb1911 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_next_from.yml @@ -0,0 +1,9 @@ +file: +- statement: + - keyword: fetch + - keyword: next + - keyword: from + - naked_identifier: curcursor + - keyword: into + - variable: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session.sql new file mode 100644 index 000000000..588a4e4f9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session.sql @@ -0,0 +1 @@ +fetch curcursor into @test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session.yml new file mode 100644 index 000000000..e10013f42 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session.yml @@ -0,0 +1,5 @@ +file: +- unparsable: + - word: fetch + - word: curcursor + - word: into diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session_multiple.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session_multiple.sql new file mode 100644 index 000000000..88507d69f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session_multiple.sql @@ -0,0 +1 @@ +fetch curcursor into @test, @test2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session_multiple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session_multiple.yml new file mode 100644 index 000000000..e10013f42 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/fetch_session_multiple.yml @@ -0,0 +1,5 @@ +file: +- unparsable: + - word: fetch + - word: curcursor + - word: into diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/flush.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/flush.sql new file mode 100644 index 000000000..8d0c1c383 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/flush.sql @@ -0,0 +1,10 @@ +FLUSH LOGS; +FLUSH NO_WRITE_TO_BINLOG BINARY LOGS, ENGINE LOGS, ERROR LOGS, GENERAL LOGS, HOSTS; +FLUSH LOCAL PRIVILEGES, OPTIMIZER_COSTS, RELAY LOGS, SLOW LOGS, STATUS, USER_RESOURCES; +FLUSH RELAY LOGS FOR CHANNEL my_channel; +FLUSH TABLES; +FLUSH TABLES WITH READ LOCK; +FLUSH TABLES table1; +FLUSH TABLES table1, `foo`.`bar`; +FLUSH TABLES table1, `foo`.`bar` WITH READ LOCK; +FLUSH TABLES table1, `foo`.`bar` FOR EXPORT; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/flush.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/flush.yml new file mode 100644 index 000000000..8331721d4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/flush.yml @@ -0,0 +1,97 @@ +file: +- statement: + - keyword: FLUSH + - keyword: LOGS +- statement_terminator: ; +- statement: + - keyword: FLUSH + - keyword: NO_WRITE_TO_BINLOG + - keyword: BINARY + - keyword: LOGS + - comma: ',' + - keyword: ENGINE + - keyword: LOGS + - comma: ',' + - keyword: ERROR + - keyword: LOGS + - comma: ',' + - keyword: GENERAL + - keyword: LOGS + - comma: ',' + - keyword: HOSTS +- statement_terminator: ; +- statement: + - keyword: FLUSH + - keyword: LOCAL + - keyword: PRIVILEGES + - comma: ',' + - keyword: OPTIMIZER_COSTS + - comma: ',' + - keyword: RELAY + - keyword: LOGS + - comma: ',' + - keyword: SLOW + - keyword: LOGS + - comma: ',' + - keyword: STATUS + - comma: ',' + - keyword: USER_RESOURCES +- statement_terminator: ; +- statement: + - keyword: FLUSH + - keyword: RELAY + - keyword: LOGS + - keyword: FOR + - keyword: CHANNEL + - object_reference: + - naked_identifier: my_channel +- statement_terminator: ; +- statement: + - keyword: FLUSH + - keyword: TABLES +- statement_terminator: ; +- statement: + - keyword: FLUSH + - keyword: TABLES + - keyword: WITH + - keyword: READ + - keyword: LOCK +- statement_terminator: ; +- statement: + - keyword: FLUSH + - keyword: TABLES + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - keyword: FLUSH + - keyword: TABLES + - table_reference: + - naked_identifier: table1 +- file: + - comma: ',' + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - semicolon: ; + - word: FLUSH + - word: TABLES + - word: table1 + - comma: ',' + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: WITH + - word: READ + - word: LOCK + - semicolon: ; + - word: FLUSH + - word: TABLES + - word: table1 + - comma: ',' + - back_quote: '`foo`' + - dot: . + - back_quote: '`bar`' + - word: FOR + - word: EXPORT + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index.sql new file mode 100644 index 000000000..281700d33 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index.sql @@ -0,0 +1 @@ +SELECT * FROM onetable FORCE INDEX (idx_index); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_index.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index.yml new file mode 100644 index 000000000..160e0dc48 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index.yml @@ -0,0 +1,23 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - unparsable: + - word: FORCE + - word: INDEX + - start_bracket: ( + - word: idx_index + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_group_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_group_by.sql new file mode 100644 index 000000000..229812045 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_group_by.sql @@ -0,0 +1 @@ +SELECT * FROM onetable FORCE INDEX FOR GROUP BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_group_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_group_by.yml new file mode 100644 index 000000000..1f50e7a3d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_group_by.yml @@ -0,0 +1,26 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - unparsable: + - word: FORCE + - word: INDEX + - word: FOR + - word: GROUP + - word: BY + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_join.sql new file mode 100644 index 000000000..7628932ea --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_join.sql @@ -0,0 +1 @@ +SELECT * FROM onetable FORCE INDEX FOR JOIN (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_join.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_join.yml new file mode 100644 index 000000000..0c28ee986 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_join.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - unparsable: + - word: FORCE + - word: INDEX + - word: FOR + - word: JOIN + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_order_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_order_by.sql new file mode 100644 index 000000000..3e8797866 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_order_by.sql @@ -0,0 +1 @@ +SELECT * FROM onetable FORCE INDEX FOR ORDER BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_order_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_order_by.yml new file mode 100644 index 000000000..14f84931d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_for_order_by.yml @@ -0,0 +1,26 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - unparsable: + - word: FORCE + - word: INDEX + - word: FOR + - word: ORDER + - word: BY + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_left_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_left_join.sql new file mode 100644 index 000000000..8e0b62fd6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_left_join.sql @@ -0,0 +1 @@ +SELECT onetable.f1, twotable.f1 FROM onetable left join twotable FORCE INDEX (idx_index) on onetable.f1 = twotable.f1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_left_join.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_left_join.yml new file mode 100644 index 000000000..33b91f6d5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_index_left_join.yml @@ -0,0 +1,45 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: onetable + - dot: . + - naked_identifier: f1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: twotable + - dot: . + - naked_identifier: f1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - join_clause: + - keyword: left + - keyword: join + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: twotable + - unparsable: + - word: FORCE + - word: INDEX + - start_bracket: ( + - word: idx_index + - end_bracket: ) + - word: on + - word: onetable + - dot: . + - word: f1 + - raw_comparison_operator: = + - word: twotable + - dot: . + - word: f1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_key.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/force_key.sql new file mode 100644 index 000000000..a351aff99 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_key.sql @@ -0,0 +1 @@ +SELECT * FROM onetable FORCE KEY (idx_index); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/force_key.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/force_key.yml new file mode 100644 index 000000000..f0c3fea16 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/force_key.yml @@ -0,0 +1,23 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - unparsable: + - word: FORCE + - word: KEY + - start_bracket: ( + - word: idx_index + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_comment.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/function_comment.sql new file mode 100644 index 000000000..038a72db8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_comment.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION `testfunction`(var1 int) +RETURNS longtext +COMMENT 'this is a comment' +DETERMINISTIC +BEGIN +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_comment.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/function_comment.yml new file mode 100644 index 000000000..8f98276d1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_comment.yml @@ -0,0 +1,17 @@ +file: +- unparsable: + - word: CREATE + - word: FUNCTION + - back_quote: '`testfunction`' + - start_bracket: ( + - word: var1 + - word: int + - end_bracket: ) + - word: RETURNS + - word: longtext + - word: COMMENT + - single_quote: '''this is a comment''' + - word: DETERMINISTIC + - word: BEGIN + - word: END + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_definer.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/function_definer.sql new file mode 100644 index 000000000..9ca72c26d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_definer.sql @@ -0,0 +1,6 @@ +CREATE DEFINER=`test`@`%` FUNCTION `testfunction`() +RETURNS longtext +DETERMINISTIC +BEGIN +SELECT 1; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_definer.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/function_definer.yml new file mode 100644 index 000000000..26ee85a02 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_definer.yml @@ -0,0 +1,6 @@ +file: +- unparsable: + - word: CREATE + - word: DEFINER + - raw_comparison_operator: = + - back_quote: '`test`' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_modifies_sql.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/function_modifies_sql.sql new file mode 100644 index 000000000..38784526d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_modifies_sql.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +MODIFIES SQL DATA +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_modifies_sql.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/function_modifies_sql.yml new file mode 100644 index 000000000..b23ac668f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_modifies_sql.yml @@ -0,0 +1,23 @@ +file: +- unparsable: + - word: CREATE + - word: FUNCTION + - back_quote: '`add`' + - start_bracket: ( + - word: test + - word: int + - end_bracket: ) + - word: RETURNS + - word: longtext + - word: DETERMINISTIC + - word: MODIFIES + - word: SQL + - word: DATA + - word: BEGIN + - word: SELECT + - numeric_literal: '1' + - plus: + + - numeric_literal: '2' + - semicolon: ; + - word: END + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_no_sql.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/function_no_sql.sql new file mode 100644 index 000000000..d4826b788 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_no_sql.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +NO SQL +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_no_sql.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/function_no_sql.yml new file mode 100644 index 000000000..e5c2e5ebc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_no_sql.yml @@ -0,0 +1,22 @@ +file: +- unparsable: + - word: CREATE + - word: FUNCTION + - back_quote: '`add`' + - start_bracket: ( + - word: test + - word: int + - end_bracket: ) + - word: RETURNS + - word: longtext + - word: DETERMINISTIC + - word: NO + - word: SQL + - word: BEGIN + - word: SELECT + - numeric_literal: '1' + - plus: + + - numeric_literal: '2' + - semicolon: ; + - word: END + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_notdeterministic.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/function_notdeterministic.sql new file mode 100644 index 000000000..611a0570c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_notdeterministic.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +NOT DETERMINISTIC +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_notdeterministic.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/function_notdeterministic.yml new file mode 100644 index 000000000..52031d926 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_notdeterministic.yml @@ -0,0 +1,21 @@ +file: +- unparsable: + - word: CREATE + - word: FUNCTION + - back_quote: '`add`' + - start_bracket: ( + - word: test + - word: int + - end_bracket: ) + - word: RETURNS + - word: longtext + - word: NOT + - word: DETERMINISTIC + - word: BEGIN + - word: SELECT + - numeric_literal: '1' + - plus: + + - numeric_literal: '2' + - semicolon: ; + - word: END + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_reads_sql.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/function_reads_sql.sql new file mode 100644 index 000000000..d5c36ff63 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_reads_sql.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +READS SQL DATA +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_reads_sql.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/function_reads_sql.yml new file mode 100644 index 000000000..6719aa846 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_reads_sql.yml @@ -0,0 +1,23 @@ +file: +- unparsable: + - word: CREATE + - word: FUNCTION + - back_quote: '`add`' + - start_bracket: ( + - word: test + - word: int + - end_bracket: ) + - word: RETURNS + - word: longtext + - word: DETERMINISTIC + - word: READS + - word: SQL + - word: DATA + - word: BEGIN + - word: SELECT + - numeric_literal: '1' + - plus: + + - numeric_literal: '2' + - semicolon: ; + - word: END + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_return.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/function_return.sql new file mode 100644 index 000000000..d0cb6926c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_return.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION `testfunction`(var1 int) +RETURNS int +DETERMINISTIC +BEGIN +RETURN (var1 + 1); +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_return.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/function_return.yml new file mode 100644 index 000000000..2af4829b0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_return.yml @@ -0,0 +1,22 @@ +file: +- unparsable: + - word: CREATE + - word: FUNCTION + - back_quote: '`testfunction`' + - start_bracket: ( + - word: var1 + - word: int + - end_bracket: ) + - word: RETURNS + - word: int + - word: DETERMINISTIC + - word: BEGIN + - word: RETURN + - start_bracket: ( + - word: var1 + - plus: + + - numeric_literal: '1' + - end_bracket: ) + - semicolon: ; + - word: END + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_definer.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_definer.sql new file mode 100644 index 000000000..c171bbbdc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_definer.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +SQL SECURITY DEFINER +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_definer.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_definer.yml new file mode 100644 index 000000000..848f24ebb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_definer.yml @@ -0,0 +1,23 @@ +file: +- unparsable: + - word: CREATE + - word: FUNCTION + - back_quote: '`add`' + - start_bracket: ( + - word: test + - word: int + - end_bracket: ) + - word: RETURNS + - word: longtext + - word: DETERMINISTIC + - word: SQL + - word: SECURITY + - word: DEFINER + - word: BEGIN + - word: SELECT + - numeric_literal: '1' + - plus: + + - numeric_literal: '2' + - semicolon: ; + - word: END + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_invoker.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_invoker.sql new file mode 100644 index 000000000..cecfe46fe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_invoker.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +SQL SECURITY INVOKER +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_invoker.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_invoker.yml new file mode 100644 index 000000000..0fb30db2e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/function_sql_security_invoker.yml @@ -0,0 +1,23 @@ +file: +- unparsable: + - word: CREATE + - word: FUNCTION + - back_quote: '`add`' + - start_bracket: ( + - word: test + - word: int + - end_bracket: ) + - word: RETURNS + - word: longtext + - word: DETERMINISTIC + - word: SQL + - word: SECURITY + - word: INVOKER + - word: BEGIN + - word: SELECT + - numeric_literal: '1' + - plus: + + - numeric_literal: '2' + - semicolon: ; + - word: END + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_local_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_local_variable.sql new file mode 100644 index 000000000..fd5e392fd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_local_variable.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION 1 _test = CLASS_ORIGIN; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_local_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_local_variable.yml new file mode 100644 index 000000000..2bccabf82 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_local_variable.yml @@ -0,0 +1,11 @@ +file: +- statement: + - keyword: GET + - keyword: DIAGNOSTICS + - keyword: CONDITION + - variable: '1' + - variable: _test + - comparison_operator: + - raw_comparison_operator: = + - keyword: CLASS_ORIGIN +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_multiple_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_multiple_variable.sql new file mode 100644 index 000000000..718ce4ff0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_multiple_variable.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION 1 _test = CLASS_ORIGIN, @test = TABLE_NAME; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_multiple_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_multiple_variable.yml new file mode 100644 index 000000000..2d08a6321 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_multiple_variable.yml @@ -0,0 +1,12 @@ +file: +- statement: + - keyword: GET + - keyword: DIAGNOSTICS + - keyword: CONDITION + - variable: '1' + - variable: _test + - comparison_operator: + - raw_comparison_operator: = + - keyword: CLASS_ORIGIN +- file: + - comma: ',' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_session_variable.sql new file mode 100644 index 000000000..104af70b2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_session_variable.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION 1 @test = CLASS_ORIGIN; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_session_variable.yml new file mode 100644 index 000000000..7f03b9e44 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_info_session_variable.yml @@ -0,0 +1,6 @@ +file: +- statement: + - keyword: GET + - keyword: DIAGNOSTICS + - keyword: CONDITION + - variable: '1' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_local_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_local_variable.sql new file mode 100644 index 000000000..2ca80746f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_local_variable.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION _test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_local_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_local_variable.yml new file mode 100644 index 000000000..43fc718f9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_local_variable.yml @@ -0,0 +1,7 @@ +file: +- statement: + - keyword: GET + - keyword: DIAGNOSTICS + - keyword: CONDITION + - variable: _test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_numeric.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_numeric.sql new file mode 100644 index 000000000..5e7371e1b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_numeric.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_numeric.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_numeric.yml new file mode 100644 index 000000000..ed2715c60 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_numeric.yml @@ -0,0 +1,7 @@ +file: +- statement: + - keyword: GET + - keyword: DIAGNOSTICS + - keyword: CONDITION + - variable: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_session_variable.sql new file mode 100644 index 000000000..73f242742 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_session_variable.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION @test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_session_variable.yml new file mode 100644 index 000000000..157eacf01 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_condition_session_variable.yml @@ -0,0 +1,5 @@ +file: +- unparsable: + - word: GET + - word: DIAGNOSTICS + - word: CONDITION diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_number.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_number.sql new file mode 100644 index 000000000..445b122fd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_number.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS @a = NUMBER CONDITION 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_number.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_number.yml new file mode 100644 index 000000000..636e4baa8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_number.yml @@ -0,0 +1,4 @@ +file: +- unparsable: + - word: GET + - word: DIAGNOSTICS diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_row_count.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_row_count.sql new file mode 100644 index 000000000..cfd9cc622 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_row_count.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS @a = ROW_COUNT CONDITION 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_row_count.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_row_count.yml new file mode 100644 index 000000000..636e4baa8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/get_diagnostics_row_count.yml @@ -0,0 +1,4 @@ +file: +- unparsable: + - word: GET + - word: DIAGNOSTICS diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/grant.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/grant.sql new file mode 100644 index 000000000..0d0486140 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/grant.sql @@ -0,0 +1,11 @@ +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO prj_svc; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO 'prj_svc'; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO "prj_svc"; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO `prj_svc`; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO 'prj_svc'@'%'; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO "prj_svc"@"%"; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO `prj_svc`@`%`; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO `prj_svc` @`%`; +GRANT ALL ON db1.* TO 'prj_svc'@'%'; +GRANT ALL PRIVILEGES ON db1.* TO 'prj_svc'@'localhost'; +GRANT ALL PRIVILEGES ON *.* TO 'prj_svc'@'%'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/grant.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/grant.yml new file mode 100644 index 000000000..99e1a2da9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/grant.yml @@ -0,0 +1,80 @@ +file: +- statement: + - access_statement: + - keyword: GRANT + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - comma: ',' + - keyword: DELETE + - comma: ',' + - keyword: SELECT + - comma: ',' + - keyword: REFERENCES + - keyword: ON + - object_reference: + - naked_identifier: prj_table + - keyword: TO + - role_reference: + - naked_identifier: prj_svc +- statement_terminator: ; +- file: + - word: GRANT + - word: INSERT + - comma: ',' + - word: UPDATE + - comma: ',' + - word: DELETE + - comma: ',' + - word: SELECT + - comma: ',' + - word: REFERENCES + - word: ON + - word: prj_table + - word: TO + - single_quote: '''prj_svc''' + - semicolon: ; + - word: GRANT + - word: INSERT + - comma: ',' + - word: UPDATE + - comma: ',' + - word: DELETE + - comma: ',' + - word: SELECT + - comma: ',' + - word: REFERENCES + - word: ON + - word: prj_table + - word: TO + - double_quote: '"prj_svc"' + - semicolon: ; + - word: GRANT + - word: INSERT + - comma: ',' + - word: UPDATE + - comma: ',' + - word: DELETE + - comma: ',' + - word: SELECT + - comma: ',' + - word: REFERENCES + - word: ON + - word: prj_table + - word: TO + - back_quote: '`prj_svc`' + - semicolon: ; + - word: GRANT + - word: INSERT + - comma: ',' + - word: UPDATE + - comma: ',' + - word: DELETE + - comma: ',' + - word: SELECT + - comma: ',' + - word: REFERENCES + - word: ON + - word: prj_table + - word: TO + - single_quote: '''prj_svc''' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_condition_name.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_condition_name.sql new file mode 100644 index 000000000..e747b33d4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_condition_name.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for conditionName +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_condition_name.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_condition_name.yml new file mode 100644 index 000000000..adaff122f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_condition_name.yml @@ -0,0 +1,16 @@ +file: +- statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - naked_identifier: conditionName + - statement: + - transaction_statement: + - keyword: begin +- file: + - word: select + - numeric_literal: '1' + - semicolon: ; + - word: end + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_error_code.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_error_code.sql new file mode 100644 index 000000000..93d0003d3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_error_code.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for 1051 +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_error_code.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_error_code.yml new file mode 100644 index 000000000..5a8648172 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_error_code.yml @@ -0,0 +1,16 @@ +file: +- statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - numeric_literal: '1051' + - statement: + - transaction_statement: + - keyword: begin +- file: + - word: select + - numeric_literal: '1' + - semicolon: ; + - word: end + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_not_found.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_not_found.sql new file mode 100644 index 000000000..1c6f21e20 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_not_found.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for not found +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_not_found.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_not_found.yml new file mode 100644 index 000000000..6f5453ec8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_not_found.yml @@ -0,0 +1,17 @@ +file: +- statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - keyword: not + - keyword: found + - statement: + - transaction_statement: + - keyword: begin +- file: + - word: select + - numeric_literal: '1' + - semicolon: ; + - word: end + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate.sql new file mode 100644 index 000000000..39de5a8c9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for SQLSTATE '1' +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate.yml new file mode 100644 index 000000000..53f47b864 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate.yml @@ -0,0 +1,17 @@ +file: +- statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - keyword: SQLSTATE + - quoted_literal: '''1''' + - statement: + - transaction_statement: + - keyword: begin +- file: + - word: select + - numeric_literal: '1' + - semicolon: ; + - word: end + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate_value.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate_value.sql new file mode 100644 index 000000000..461c3e12f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate_value.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for SQLSTATE VALUE '1' +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate_value.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate_value.yml new file mode 100644 index 000000000..41704aba3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlstate_value.yml @@ -0,0 +1,18 @@ +file: +- statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - keyword: SQLSTATE + - keyword: VALUE + - quoted_literal: '''1''' + - statement: + - transaction_statement: + - keyword: begin +- file: + - word: select + - numeric_literal: '1' + - semicolon: ; + - word: end + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlwarning.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlwarning.sql new file mode 100644 index 000000000..8e2bc3df1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlwarning.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for sqlwarning +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlwarning.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlwarning.yml new file mode 100644 index 000000000..74f01b405 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/handler_sqlwarning.yml @@ -0,0 +1,16 @@ +file: +- statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - keyword: sqlwarning + - statement: + - transaction_statement: + - keyword: begin +- file: + - word: select + - numeric_literal: '1' + - semicolon: ; + - word: end + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/help_statement.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/help_statement.sql new file mode 100644 index 000000000..0857cd415 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/help_statement.sql @@ -0,0 +1,6 @@ +HELP 'contents'; +HELP 'data types'; +HELP 'ascii'; +HELP 'create table'; +HELP 'status'; +HELP 'functions'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/help_statement.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/help_statement.yml new file mode 100644 index 000000000..96800f885 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/help_statement.yml @@ -0,0 +1,25 @@ +file: +- statement: + - keyword: HELP + - quoted_literal: '''contents''' +- statement_terminator: ; +- statement: + - keyword: HELP + - quoted_literal: '''data types''' +- statement_terminator: ; +- statement: + - keyword: HELP + - quoted_literal: '''ascii''' +- statement_terminator: ; +- statement: + - keyword: HELP + - quoted_literal: '''create table''' +- statement_terminator: ; +- statement: + - keyword: HELP + - quoted_literal: '''status''' +- statement_terminator: ; +- statement: + - keyword: HELP + - quoted_literal: '''functions''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/hexadecimal_literal.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/hexadecimal_literal.sql new file mode 100644 index 000000000..d029ee2b8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/hexadecimal_literal.sql @@ -0,0 +1,6 @@ +SELECT X'01AF'; +SELECT X'01af'; +SELECT x'01AF'; +SELECT x'01af'; +SELECT 0x01AF; +SELECT 0x01af; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/hexadecimal_literal.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/hexadecimal_literal.yml new file mode 100644 index 000000000..367b4682f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/hexadecimal_literal.yml @@ -0,0 +1,57 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - data_type: + - data_type_identifier: X + - quoted_literal: '''01AF''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - data_type: + - data_type_identifier: X + - quoted_literal: '''01af''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - data_type: + - data_type_identifier: x + - quoted_literal: '''01AF''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - data_type: + - data_type_identifier: x + - quoted_literal: '''01af''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: '0x01AF' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: '0x01af' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/if.sql new file mode 100644 index 000000000..51a10d001 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if.sql @@ -0,0 +1,4 @@ +if (x = 0) then +set @errmsg = ''; +select 1; +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/if.yml new file mode 100644 index 000000000..4ef853dec --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if.yml @@ -0,0 +1,10 @@ +file: +- unparsable: + - word: if + - start_bracket: ( + - word: x + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - word: then + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_else.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/if_else.sql new file mode 100644 index 000000000..ade8a36c1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_else.sql @@ -0,0 +1,5 @@ +if (x = 0) then +set @errmsg = ''; +select 1; +else +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_else.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/if_else.yml new file mode 100644 index 000000000..4ef853dec --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_else.yml @@ -0,0 +1,10 @@ +file: +- unparsable: + - word: if + - start_bracket: ( + - word: x + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - word: then + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_elseif.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/if_elseif.sql new file mode 100644 index 000000000..3350218ee --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_elseif.sql @@ -0,0 +1,8 @@ +if (x = 0) then +set @errmsg = ''; +select 1; +elseif (x = 1) then +set _test = 1; +else +select 2; +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_elseif.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/if_elseif.yml new file mode 100644 index 000000000..4ef853dec --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_elseif.yml @@ -0,0 +1,10 @@ +file: +- unparsable: + - word: if + - start_bracket: ( + - word: x + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - word: then + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_multiple_expression.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/if_multiple_expression.sql new file mode 100644 index 000000000..42682cdad --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_multiple_expression.sql @@ -0,0 +1,4 @@ +if ((select count(*) from table1) = 0 and x = 1) then +set @errmsg = ''; +select 1; +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_multiple_expression.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/if_multiple_expression.yml new file mode 100644 index 000000000..3061525f8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_multiple_expression.yml @@ -0,0 +1,22 @@ +file: +- unparsable: + - word: if + - start_bracket: ( + - start_bracket: ( + - word: select + - word: count + - start_bracket: ( + - star: '*' + - end_bracket: ) + - word: from + - word: table1 + - end_bracket: ) + - raw_comparison_operator: = + - numeric_literal: '0' + - word: and + - word: x + - raw_comparison_operator: = + - numeric_literal: '1' + - end_bracket: ) + - word: then + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_nested.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/if_nested.sql new file mode 100644 index 000000000..59a50cc93 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_nested.sql @@ -0,0 +1,7 @@ +if (x = 0) then +select 0; +if (y = 1) then +set @errmsg = ''; +select 1; +end if; +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_nested.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/if_nested.yml new file mode 100644 index 000000000..54d0d7f78 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_nested.yml @@ -0,0 +1,30 @@ +file: +- statement: + - keyword: if + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - keyword: then + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '0' +- statement_terminator: ; +- file: + - word: if + - start_bracket: ( + - word: y + - raw_comparison_operator: = + - numeric_literal: '1' + - end_bracket: ) + - word: then + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/if_session_variable.sql new file mode 100644 index 000000000..df7afe915 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_session_variable.sql @@ -0,0 +1 @@ +if (@x = 0) then set @b = ''; select 1; end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/if_session_variable.yml new file mode 100644 index 000000000..c68b5e803 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_session_variable.yml @@ -0,0 +1,4 @@ +file: +- unparsable: + - word: if + - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_subquery_expression.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/if_subquery_expression.sql new file mode 100644 index 000000000..61fd6fee1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_subquery_expression.sql @@ -0,0 +1,4 @@ +if ((select count(*) from table1) = 0) then +set @errmsg = ''; +select 1; +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/if_subquery_expression.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/if_subquery_expression.yml new file mode 100644 index 000000000..be459f23c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/if_subquery_expression.yml @@ -0,0 +1,18 @@ +file: +- unparsable: + - word: if + - start_bracket: ( + - start_bracket: ( + - word: select + - word: count + - start_bracket: ( + - star: '*' + - end_bracket: ) + - word: from + - word: table1 + - end_bracket: ) + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - word: then + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index.sql new file mode 100644 index 000000000..8fc5c7e81 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index.sql @@ -0,0 +1 @@ +SELECT * FROM onetable IGNORE INDEX (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index.yml new file mode 100644 index 000000000..a00caaa4b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index.yml @@ -0,0 +1,23 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - unparsable: + - word: IGNORE + - word: INDEX + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_group_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_group_by.sql new file mode 100644 index 000000000..49fb323cf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_group_by.sql @@ -0,0 +1 @@ +SELECT * FROM onetable IGNORE INDEX FOR GROUP BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_group_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_group_by.yml new file mode 100644 index 000000000..d1e04fe45 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_group_by.yml @@ -0,0 +1,26 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - unparsable: + - word: IGNORE + - word: INDEX + - word: FOR + - word: GROUP + - word: BY + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_join.sql new file mode 100644 index 000000000..6484ba5a9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_join.sql @@ -0,0 +1 @@ +SELECT * FROM onetable IGNORE INDEX FOR JOIN (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_join.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_join.yml new file mode 100644 index 000000000..5e11dc258 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_join.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - unparsable: + - word: IGNORE + - word: INDEX + - word: FOR + - word: JOIN + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_order_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_order_by.sql new file mode 100644 index 000000000..1120499ed --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_order_by.sql @@ -0,0 +1 @@ +SELECT * FROM onetable IGNORE INDEX FOR ORDER BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_order_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_order_by.yml new file mode 100644 index 000000000..a0b330eac --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_index_for_order_by.yml @@ -0,0 +1,26 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - unparsable: + - word: IGNORE + - word: INDEX + - word: FOR + - word: ORDER + - word: BY + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_key.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_key.sql new file mode 100644 index 000000000..a0e51785d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_key.sql @@ -0,0 +1 @@ +SELECT * FROM onetable IGNORE KEY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_key.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_key.yml new file mode 100644 index 000000000..96fe6381e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/ignore_key.yml @@ -0,0 +1,23 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - unparsable: + - word: IGNORE + - word: KEY + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/insert.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/insert.sql new file mode 100644 index 000000000..e476d6bb2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/insert.sql @@ -0,0 +1,31 @@ +INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6); + +INSERT INTO t1 +SELECT * FROM (SELECT c, c+d AS e FROM t2) AS dt; + +INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6) AS t2 +ON DUPLICATE KEY UPDATE c = t2.a+t2.b; + +INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6) AS t2 +ON DUPLICATE KEY UPDATE a = VALUES(a), b = VALUES(b); + +INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6) AS t2(m,n,p) +ON DUPLICATE KEY UPDATE c = m+n; + +INSERT INTO t1 +SELECT * FROM (SELECT c, c+d AS e FROM t2) AS dt +ON DUPLICATE KEY UPDATE b = e; + +INSERT INTO t1 +SELECT * FROM (SELECT c, c+d AS e FROM t2) +ON DUPLICATE KEY UPDATE b = e; + +INSERT INTO t1 (a,b,c) +TABLE t2 as t3(m,n,p) +ON DUPLICATE KEY UPDATE b = n+p; + +INSERT INTO t1 SET a=1,b=2,c=3 AS t2 +ON DUPLICATE KEY UPDATE c = t2.a+t2.b; + +INSERT INTO t1 SET a=1,b=2,c=3 AS t2(m,n,p) +ON DUPLICATE KEY UPDATE c = m+n, b = n+p; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/insert.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/insert.yml new file mode 100644 index 000000000..6e14168af --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/insert.yml @@ -0,0 +1,385 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - comma: ',' + - column_reference: + - naked_identifier: c + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: c + - binary_operator: + + - column_reference: + - naked_identifier: d + - keyword: AS + - naked_identifier: e + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - end_bracket: ) + - keyword: AS + - naked_identifier: dt +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - comma: ',' + - column_reference: + - naked_identifier: c + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_bracket: ) +- file: + - word: AS + - word: t2 + - word: ON + - word: DUPLICATE + - word: KEY + - word: UPDATE + - word: c + - raw_comparison_operator: = + - word: t2 + - dot: . + - word: a + - plus: + + - word: t2 + - dot: . + - word: b + - semicolon: ; + - word: INSERT + - word: INTO + - word: t1 + - start_bracket: ( + - word: a + - comma: ',' + - word: b + - comma: ',' + - word: c + - end_bracket: ) + - word: VALUES + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_bracket: ) + - comma: ',' + - start_bracket: ( + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_bracket: ) + - word: AS + - word: t2 + - word: ON + - word: DUPLICATE + - word: KEY + - word: UPDATE + - word: a + - raw_comparison_operator: = + - word: VALUES + - start_bracket: ( + - word: a + - end_bracket: ) + - comma: ',' + - word: b + - raw_comparison_operator: = + - word: VALUES + - start_bracket: ( + - word: b + - end_bracket: ) + - semicolon: ; + - word: INSERT + - word: INTO + - word: t1 + - start_bracket: ( + - word: a + - comma: ',' + - word: b + - comma: ',' + - word: c + - end_bracket: ) + - word: VALUES + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_bracket: ) + - comma: ',' + - start_bracket: ( + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_bracket: ) + - word: AS + - word: t2 + - start_bracket: ( + - word: m + - comma: ',' + - word: n + - comma: ',' + - word: p + - end_bracket: ) + - word: ON + - word: DUPLICATE + - word: KEY + - word: UPDATE + - word: c + - raw_comparison_operator: = + - word: m + - plus: + + - word: n + - semicolon: ; + - word: INSERT + - word: INTO + - word: t1 + - word: SELECT + - star: '*' + - word: FROM + - start_bracket: ( + - word: SELECT + - word: c + - comma: ',' + - word: c + - plus: + + - word: d + - word: AS + - word: e + - word: FROM + - word: t2 + - end_bracket: ) + - word: AS + - word: dt + - word: ON + - word: DUPLICATE + - word: KEY + - word: UPDATE + - word: b + - raw_comparison_operator: = + - word: e + - semicolon: ; + - word: INSERT + - word: INTO + - word: t1 + - word: SELECT + - star: '*' + - word: FROM + - start_bracket: ( + - word: SELECT + - word: c + - comma: ',' + - word: c + - plus: + + - word: d + - word: AS + - word: e + - word: FROM + - word: t2 + - end_bracket: ) + - word: ON + - word: DUPLICATE + - word: KEY + - word: UPDATE + - word: b + - raw_comparison_operator: = + - word: e + - semicolon: ; + - word: INSERT + - word: INTO + - word: t1 + - start_bracket: ( + - word: a + - comma: ',' + - word: b + - comma: ',' + - word: c + - end_bracket: ) + - word: TABLE + - word: t2 + - word: as + - word: t3 + - start_bracket: ( + - word: m + - comma: ',' + - word: n + - comma: ',' + - word: p + - end_bracket: ) + - word: ON + - word: DUPLICATE + - word: KEY + - word: UPDATE + - word: b + - raw_comparison_operator: = + - word: n + - plus: + + - word: p + - semicolon: ; + - word: INSERT + - word: INTO + - word: t1 + - word: SET + - word: a + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - word: b + - raw_comparison_operator: = + - numeric_literal: '2' + - comma: ',' + - word: c + - raw_comparison_operator: = + - numeric_literal: '3' + - word: AS + - word: t2 + - word: ON + - word: DUPLICATE + - word: KEY + - word: UPDATE + - word: c + - raw_comparison_operator: = + - word: t2 + - dot: . + - word: a + - plus: + + - word: t2 + - dot: . + - word: b + - semicolon: ; + - word: INSERT + - word: INTO + - word: t1 + - word: SET + - word: a + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - word: b + - raw_comparison_operator: = + - numeric_literal: '2' + - comma: ',' + - word: c + - raw_comparison_operator: = + - numeric_literal: '3' + - word: AS + - word: t2 + - start_bracket: ( + - word: m + - comma: ',' + - word: n + - comma: ',' + - word: p + - end_bracket: ) + - word: ON + - word: DUPLICATE + - word: KEY + - word: UPDATE + - word: c + - raw_comparison_operator: = + - word: m + - plus: + + - word: n + - comma: ',' + - word: b + - raw_comparison_operator: = + - word: n + - plus: + + - word: p + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/interval.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/interval.sql new file mode 100644 index 000000000..0ca2c7e95 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/interval.sql @@ -0,0 +1,23 @@ +SELECT DATE_ADD(CURDATE(), INTERVAL -30 DAY); + +SELECT SUBDATE('2008-01-02', INTERVAL 31 DAY); + +SELECT ADDDATE(CURDATE(), INTERVAL -30 DAY); + +SELECT DATE_SUB('1992-12-31 23:59:59.000002', INTERVAL '1.999999' SECOND_MICROSECOND); + +SELECT DATE_ADD('2100-12-31 23:59:59', INTERVAL '1:1' MINUTE_SECOND); + +SELECT DATE_ADD(CURDATE(), INTERVAL 7 * 4 DAY); + +SELECT + ADDDATE(CURDATE(), INTERVAL col1 DAY) +FROM + tbl1 +; + +SELECT + SUBDATE(CURDATE(), INTERVAL col1 + col2 DAY) +FROM + tbl1 +; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/interval.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/interval.yml new file mode 100644 index 000000000..dec56814a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/interval.yml @@ -0,0 +1,204 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATE_ADD + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: CURDATE + - bracketed: + - start_bracket: ( + - end_bracket: ) + - unparsable: + - comma: ',' + - word: INTERVAL + - minus: '-' + - numeric_literal: '30' + - word: DAY + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUBDATE + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2008-01-02''' + - comma: ',' + - expression: + - interval_expression: + - keyword: INTERVAL + - numeric_literal: '31' + - date_part: DAY + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ADDDATE + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: CURDATE + - bracketed: + - start_bracket: ( + - end_bracket: ) + - unparsable: + - comma: ',' + - word: INTERVAL + - minus: '-' + - numeric_literal: '30' + - word: DAY + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATE_SUB + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''1992-12-31 23:59:59.000002''' + - comma: ',' + - expression: + - keyword: INTERVAL + - date_constructor_literal: '''1.999999''' + - unparsable: + - word: SECOND_MICROSECOND + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATE_ADD + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2100-12-31 23:59:59''' + - comma: ',' + - expression: + - keyword: INTERVAL + - date_constructor_literal: '''1:1''' + - unparsable: + - word: MINUTE_SECOND + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATE_ADD + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: CURDATE + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - data_type: + - data_type_identifier: INTERVAL + - numeric_literal: '7' + - binary_operator: '*' + - numeric_literal: '4' + - expression: + - column_reference: + - naked_identifier: DAY + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ADDDATE + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: CURDATE + - bracketed: + - start_bracket: ( + - end_bracket: ) + - unparsable: + - comma: ',' + - word: INTERVAL + - word: col1 + - word: DAY + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUBDATE + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: CURDATE + - bracketed: + - start_bracket: ( + - end_bracket: ) + - unparsable: + - comma: ',' + - word: INTERVAL + - word: col1 + - plus: + + - word: col2 + - word: DAY + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/json.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/json.sql new file mode 100644 index 000000000..b9236365a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/json.sql @@ -0,0 +1,16 @@ +CREATE TABLE facts (sentence JSON); + +INSERT INTO facts VALUES +(JSON_OBJECT("mascot", "Our mascot is a dolphin named \"Sakila\".")); + +SELECT sentence->"$.mascot" FROM facts; + +SELECT sentence->'$.mascot' FROM facts; + +SELECT sentence->>"$.mascot" FROM facts; + +SELECT sentence->>'$.mascot' FROM facts; + +SELECT sentence FROM facts WHERE JSON_TYPE(sentence->"$.mascot") = "NULL"; + +SELECT sentence FROM facts WHERE sentence->"$.mascot" IS NULL; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/json.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/json.yml new file mode 100644 index 000000000..aed1640be --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/json.yml @@ -0,0 +1,179 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: facts + - bracketed: + - start_bracket: ( + - naked_identifier: sentence + - data_type: + - data_type_identifier: JSON + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: facts + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: JSON_OBJECT + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '"mascot"' + - comma: ',' + - expression: + - column_reference: + - quoted_identifier: '"Our mascot is a dolphin named \"Sakila\"."' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: sentence + - unparsable: + - minus: '-' + - raw_comparison_operator: '>' + - double_quote: '"$.mascot"' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: sentence + - unparsable: + - minus: '-' + - raw_comparison_operator: '>' + - single_quote: '''$.mascot''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: sentence + - unparsable: + - minus: '-' + - raw_comparison_operator: '>' + - raw_comparison_operator: '>' + - double_quote: '"$.mascot"' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: sentence + - unparsable: + - minus: '-' + - raw_comparison_operator: '>' + - raw_comparison_operator: '>' + - single_quote: '''$.mascot''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: sentence + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts + - where_clause: + - keyword: WHERE + - expression: + - function: + - function_name: + - function_name_identifier: JSON_TYPE + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sentence + - unparsable: + - minus: '-' + - raw_comparison_operator: '>' + - double_quote: '"$.mascot"' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - quoted_identifier: '"NULL"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: sentence + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: sentence + - unparsable: + - minus: '-' + - raw_comparison_operator: '>' + - double_quote: '"$.mascot"' + - word: IS + - word: 'NULL' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/load_data.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/load_data.sql new file mode 100644 index 000000000..c55350c66 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/load_data.sql @@ -0,0 +1,31 @@ +LOAD DATA INFILE '/var/lib/mysql-files/libaccess.csv' INTO TABLE libaccess FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES; +LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table; +LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table PARTITION (partition_name); +LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test + FIELDS TERMINATED BY ',' LINES STARTING BY 'xxx'; +LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES; +LOAD DATA INFILE 'data.txt' INTO TABLE table2 + FIELDS TERMINATED BY ','; +LOAD DATA INFILE 'data.txt' INTO TABLE table2 + FIELDS TERMINATED BY '\t'; +LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name + FIELDS TERMINATED BY ',' ENCLOSED BY '"' + LINES TERMINATED BY '\r\n' + IGNORE 1 LINES; +LOAD DATA INFILE '/tmp/jokes.txt' INTO TABLE jokes + FIELDS TERMINATED BY '' + LINES TERMINATED BY '\n%%\n' (joke); +LOAD DATA INFILE 'persondata.txt' INTO TABLE persondata; +LOAD DATA INFILE 'file.txt' + INTO TABLE t1 + (column1, @var1) + SET column2 = @var1/100; +LOAD DATA INFILE 'file.txt' + INTO TABLE t1 + (column1, column2) + SET column3 = CURRENT_TIMESTAMP; +LOAD DATA INFILE 'file.txt' + INTO TABLE t1 + (column1, @dummy, column2, @dummy, column3); +LOAD DATA INFILE '/local/access_log' INTO TABLE tbl_name + FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/load_data.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/load_data.yml new file mode 100644 index 000000000..c14665833 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/load_data.yml @@ -0,0 +1,155 @@ +file: +- unparsable: + - word: LOAD + - word: DATA + - word: INFILE + - single_quote: '''/var/lib/mysql-files/libaccess.csv''' + - word: INTO + - word: TABLE + - word: libaccess + - word: FIELDS + - word: TERMINATED + - word: BY + - single_quote: '''\t''' + - word: OPTIONALLY + - word: ENCLOSED + - word: BY + - single_quote: '''"''' + - word: IGNORE + - numeric_literal: '1' + - word: LINES + - semicolon: ; + - word: LOAD + - word: DATA + - word: INFILE + - single_quote: '''data.txt''' + - word: INTO + - word: TABLE + - word: db2 + - dot: . + - word: my_table + - semicolon: ; + - word: LOAD + - word: DATA + - word: INFILE + - single_quote: '''data.txt''' + - word: INTO + - word: TABLE + - word: db2 + - dot: . + - word: my_table + - word: PARTITION + - start_bracket: ( + - word: partition_name + - end_bracket: ) + - semicolon: ; + - word: LOAD + - word: DATA + - word: INFILE + - single_quote: '''/tmp/test.txt''' + - word: INTO + - word: TABLE + - word: test + - word: FIELDS + - word: TERMINATED + - word: BY + - single_quote: ''',''' + - word: LINES + - word: STARTING + - word: BY + - single_quote: '''xxx''' + - semicolon: ; + - word: LOAD + - word: DATA + - word: INFILE + - single_quote: '''/tmp/test.txt''' + - word: INTO + - word: TABLE + - word: test + - word: IGNORE + - numeric_literal: '1' + - word: LINES + - semicolon: ; + - word: LOAD + - word: DATA + - word: INFILE + - single_quote: '''data.txt''' + - word: INTO + - word: TABLE + - word: table2 + - word: FIELDS + - word: TERMINATED + - word: BY + - single_quote: ''',''' + - semicolon: ; + - word: LOAD + - word: DATA + - word: INFILE + - single_quote: '''data.txt''' + - word: INTO + - word: TABLE + - word: table2 + - word: FIELDS + - word: TERMINATED + - word: BY + - single_quote: '''\t''' + - semicolon: ; + - word: LOAD + - word: DATA + - word: INFILE + - single_quote: '''data.txt''' + - word: INTO + - word: TABLE + - word: tbl_name + - word: FIELDS + - word: TERMINATED + - word: BY + - single_quote: ''',''' + - word: ENCLOSED + - word: BY + - single_quote: '''"''' + - word: LINES + - word: TERMINATED + - word: BY + - single_quote: '''\r\n''' + - word: IGNORE + - numeric_literal: '1' + - word: LINES + - semicolon: ; + - word: LOAD + - word: DATA + - word: INFILE + - single_quote: '''/tmp/jokes.txt''' + - word: INTO + - word: TABLE + - word: jokes + - word: FIELDS + - word: TERMINATED + - word: BY + - single_quote: '''''' + - word: LINES + - word: TERMINATED + - word: BY + - single_quote: '''\n%%\n''' + - start_bracket: ( + - word: joke + - end_bracket: ) + - semicolon: ; + - word: LOAD + - word: DATA + - word: INFILE + - single_quote: '''persondata.txt''' + - word: INTO + - word: TABLE + - word: persondata + - semicolon: ; + - word: LOAD + - word: DATA + - word: INFILE + - single_quote: '''file.txt''' + - word: INTO + - word: TABLE + - word: t1 + - start_bracket: ( + - word: column1 + - comma: ',' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/loop_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_label.sql new file mode 100644 index 000000000..8d109e400 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_label.sql @@ -0,0 +1 @@ +iteration:loop select 1; iterate iteration; leave iteration; end loop iteration; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/loop_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_label.yml new file mode 100644 index 000000000..187197540 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_label.yml @@ -0,0 +1,24 @@ +file: +- statement: + - naked_identifier: iteration + - colon: ':' + - keyword: loop + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - keyword: iterate + - naked_identifier: iteration +- statement_terminator: ; +- file: + - word: leave + - word: iteration + - semicolon: ; + - word: end + - word: loop + - word: iteration + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/loop_multiple_statements.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_multiple_statements.sql new file mode 100644 index 000000000..263ee2e17 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_multiple_statements.sql @@ -0,0 +1 @@ +loop select 1; select * from onetable; end loop; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/loop_multiple_statements.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_multiple_statements.yml new file mode 100644 index 000000000..70149e865 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_multiple_statements.yml @@ -0,0 +1,30 @@ +file: +- statement: + - keyword: loop + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable +- statement_terminator: ; +- statement: + - keyword: end + - keyword: loop +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/loop_no_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_no_label.sql new file mode 100644 index 000000000..557ebe302 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_no_label.sql @@ -0,0 +1 @@ +loop select 1; end loop; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/loop_no_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_no_label.yml new file mode 100644 index 000000000..12a27d8f8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/loop_no_label.yml @@ -0,0 +1,14 @@ +file: +- statement: + - keyword: loop + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - keyword: end + - keyword: loop +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/nested_begin.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/nested_begin.sql new file mode 100644 index 000000000..037fa004a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/nested_begin.sql @@ -0,0 +1,5 @@ +blocks:BEGIN +nest:begin +set @abc = 1; +end nest; +END blocks~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/nested_begin.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/nested_begin.yml new file mode 100644 index 000000000..eda7e121b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/nested_begin.yml @@ -0,0 +1,9 @@ +file: +- unparsable: + - word: blocks + - colon: ':' + - word: BEGIN + - word: nest + - colon: ':' + - word: begin + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/open.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/open.sql new file mode 100644 index 000000000..b8c64db7a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/open.sql @@ -0,0 +1 @@ +open curcursor; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/open.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/open.yml new file mode 100644 index 000000000..09b86f11f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/open.yml @@ -0,0 +1,5 @@ +file: +- statement: + - keyword: open + - naked_identifier: curcursor +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/open_qualified.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/open_qualified.sql new file mode 100644 index 000000000..9247612d2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/open_qualified.sql @@ -0,0 +1 @@ +open `curcursor`; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/open_qualified.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/open_qualified.yml new file mode 100644 index 000000000..f47febedb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/open_qualified.yml @@ -0,0 +1,5 @@ +file: +- unparsable: + - word: open + - back_quote: '`curcursor`' + - semicolon: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/optimize_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/optimize_table.sql new file mode 100644 index 000000000..e7bda7ad2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/optimize_table.sql @@ -0,0 +1,11 @@ +OPTIMIZE TABLE some_table; + +OPTIMIZE TABLE some_table1, some_table2; + +OPTIMIZE NO_WRITE_TO_BINLOG TABLE some_table; + +OPTIMIZE NO_WRITE_TO_BINLOG TABLE some_table1, some_table2; + +OPTIMIZE LOCAL TABLE some_table; + +OPTIMIZE LOCAL TABLE some_table1, some_table2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/optimize_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/optimize_table.yml new file mode 100644 index 000000000..ba3f334d3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/optimize_table.yml @@ -0,0 +1,50 @@ +file: +- statement: + - keyword: OPTIMIZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - keyword: OPTIMIZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - keyword: OPTIMIZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - keyword: OPTIMIZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - keyword: OPTIMIZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - keyword: OPTIMIZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_local_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_local_variable.sql new file mode 100644 index 000000000..06820e2e9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_local_variable.sql @@ -0,0 +1 @@ +PREPARE test FROM _test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_local_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_local_variable.yml new file mode 100644 index 000000000..7f230ced8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_local_variable.yml @@ -0,0 +1,7 @@ +file: +- statement: + - keyword: PREPARE + - naked_identifier: test + - keyword: FROM + - variable: _test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_session_variable.sql new file mode 100644 index 000000000..aa1b0aab6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_session_variable.sql @@ -0,0 +1 @@ +PREPARE test FROM @test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_session_variable.yml new file mode 100644 index 000000000..732de2deb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_session_variable.yml @@ -0,0 +1,5 @@ +file: +- unparsable: + - word: PREPARE + - word: test + - word: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_statement.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_statement.sql new file mode 100644 index 000000000..a5ea424c7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_statement.sql @@ -0,0 +1 @@ +PREPARE test FROM 'select 1;'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_statement.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_statement.yml new file mode 100644 index 000000000..50b41c251 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/prepare_statement.yml @@ -0,0 +1,7 @@ +file: +- statement: + - keyword: PREPARE + - naked_identifier: test + - keyword: FROM + - quoted_literal: '''select 1;''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_definer.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_definer.sql new file mode 100644 index 000000000..62834e30c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_definer.sql @@ -0,0 +1,3 @@ +CREATE DEFINER=`test`@`%` PROCEDURE `testprocedure`() +BEGIN +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_definer.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_definer.yml new file mode 100644 index 000000000..26ee85a02 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_definer.yml @@ -0,0 +1,6 @@ +file: +- unparsable: + - word: CREATE + - word: DEFINER + - raw_comparison_operator: = + - back_quote: '`test`' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_in_param.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_in_param.sql new file mode 100644 index 000000000..c5b8deb44 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_in_param.sql @@ -0,0 +1,3 @@ +CREATE PROCEDURE `testprocedure`(in test int) +BEGIN +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_in_param.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_in_param.yml new file mode 100644 index 000000000..e33bba49b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_in_param.yml @@ -0,0 +1,13 @@ +file: +- unparsable: + - word: CREATE + - word: PROCEDURE + - back_quote: '`testprocedure`' + - start_bracket: ( + - word: in + - word: test + - word: int + - end_bracket: ) + - word: BEGIN + - word: END + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_inout_param.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_inout_param.sql new file mode 100644 index 000000000..f705521fc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_inout_param.sql @@ -0,0 +1,3 @@ +CREATE PROCEDURE `testprocedure`(inout test int) +BEGIN +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_inout_param.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_inout_param.yml new file mode 100644 index 000000000..a418f8203 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_inout_param.yml @@ -0,0 +1,13 @@ +file: +- unparsable: + - word: CREATE + - word: PROCEDURE + - back_quote: '`testprocedure`' + - start_bracket: ( + - word: inout + - word: test + - word: int + - end_bracket: ) + - word: BEGIN + - word: END + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_out_param.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_out_param.sql new file mode 100644 index 000000000..4585500b9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_out_param.sql @@ -0,0 +1,3 @@ +CREATE PROCEDURE `testprocedure`(out test int) +BEGIN +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_out_param.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_out_param.yml new file mode 100644 index 000000000..0891bd7b7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/procedure_out_param.yml @@ -0,0 +1,13 @@ +file: +- unparsable: + - word: CREATE + - word: PROCEDURE + - back_quote: '`testprocedure`' + - start_bracket: ( + - word: out + - word: test + - word: int + - end_bracket: ) + - word: BEGIN + - word: END + - like_operator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/purge_binary_logs.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/purge_binary_logs.sql new file mode 100644 index 000000000..d1f5c13ac --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/purge_binary_logs.sql @@ -0,0 +1,7 @@ +PURGE BINARY LOGS TO 'mysql-bin.010'; + +PURGE BINARY LOGS BEFORE '2019-04-02 22:46:26'; +PURGE BINARY LOGS BEFORE TIMESTAMP '2019-04-02 22:46:26'; + +PURGE BINARY LOGS BEFORE 19830905132800; +PURGE BINARY LOGS BEFORE TIMESTAMP 19830905132800; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/purge_binary_logs.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/purge_binary_logs.yml new file mode 100644 index 000000000..dbfad4d87 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/purge_binary_logs.yml @@ -0,0 +1,43 @@ +file: +- statement: + - keyword: PURGE + - keyword: BINARY + - keyword: LOGS + - keyword: TO + - quoted_literal: '''mysql-bin.010''' +- statement_terminator: ; +- statement: + - keyword: PURGE + - keyword: BINARY + - keyword: LOGS + - keyword: BEFORE + - expression: + - quoted_literal: '''2019-04-02 22:46:26''' +- statement_terminator: ; +- statement: + - keyword: PURGE + - keyword: BINARY + - keyword: LOGS + - keyword: BEFORE + - expression: + - keyword: TIMESTAMP + - date_constructor_literal: '''2019-04-02 22:46:26''' +- statement_terminator: ; +- statement: + - keyword: PURGE + - keyword: BINARY + - keyword: LOGS + - keyword: BEFORE + - expression: + - numeric_literal: '19830905132800' +- statement_terminator: ; +- statement: + - keyword: PURGE + - keyword: BINARY + - keyword: LOGS + - keyword: BEFORE + - expression: + - data_type: + - keyword: TIMESTAMP + - numeric_literal: '19830905132800' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/quoted_literal.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/quoted_literal.sql new file mode 100644 index 000000000..a2ee306f0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/quoted_literal.sql @@ -0,0 +1,75 @@ +SELECT ''; + +SELECT ""; + +SELECT ''''; + +SELECT """"; + +SELECT ' + +'; + +SELECT " + +"; + +SELECT '''aaa'''; + +SELECT """aaa"""; + +SELECT ' +'' +'; + +SELECT " +"" +"; + +SELECT 'foo' +'bar'; + +SELECT "foo" +"bar"; + +SELECT 'foo' 'bar'; + +SELECT "foo" "bar"; + +SELECT 'foo' "bar"; + +SELECT 'foo' + + +'bar'; + +SELECT "foo" + + +"bar"; + +SELECT 'foo' -- some comment +'bar'; + +SELECT "foo" -- some comment +"bar"; + +SELECT 'foo' /* some comment */ 'bar'; + +SELECT "foo" /* some comment */ "bar"; + +UPDATE table1 SET column1 = 'baz\'s'; + +UPDATE table1 SET column1 = "baz\"s"; + +SELECT 'terminating MySQL-y escaped single-quote bazs\''; + +SELECT "terminating MySQL-y escaped double-quote bazs\""; + +SELECT 'terminating ANSI-ish escaped single-quote '''; + +SELECT "terminating ANSI-ish escaped double-quote """; + +SELECT '\\'; + +SELECT "\\"; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/quoted_literal.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/quoted_literal.yml new file mode 100644 index 000000000..147a3c5ab --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/quoted_literal.yml @@ -0,0 +1,260 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '""' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''''''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '""' + - quoted_identifier: '""' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: |- + ' + + ' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: |- + " + + " +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''''''aaa''''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '""' + - quoted_identifier: '"aaa"' + - unparsable: + - double_quote: '""' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: |- + ' + '' + ' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: |- + " + " + - quoted_identifier: |- + " + " +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_identifier: '''bar''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '"foo"' + - quoted_identifier: '"bar"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_identifier: '''bar''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '"foo"' + - quoted_identifier: '"bar"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_identifier: '"bar"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_identifier: '''bar''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '"foo"' + - quoted_identifier: '"bar"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_identifier: '''bar''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '"foo"' + - quoted_identifier: '"bar"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_identifier: '''bar''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '"foo"' + - quoted_identifier: '"bar"' +- statement_terminator: ; +- statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: table1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: column1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''baz\''s''' +- statement_terminator: ; +- statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: table1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: column1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - quoted_identifier: '"baz\"s"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''terminating MySQL-y escaped single-quote bazs\''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '"terminating MySQL-y escaped double-quote bazs\""' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''terminating ANSI-ish escaped single-quote ''''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '"terminating ANSI-ish escaped double-quote "' + - quoted_identifier: '""' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''\\''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '"\\"' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/rename_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/rename_table.sql new file mode 100644 index 000000000..3871afeff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/rename_table.sql @@ -0,0 +1,2 @@ +RENAME TABLE old_table TO new_table; +RENAME TABLE old_table1 TO new_table1, old_table2 TO new_table2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/rename_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/rename_table.yml new file mode 100644 index 000000000..dd4c03855 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/rename_table.yml @@ -0,0 +1,25 @@ +file: +- statement: + - keyword: RENAME + - keyword: TABLE + - table_reference: + - naked_identifier: old_table + - keyword: TO + - table_reference: + - naked_identifier: new_table +- statement_terminator: ; +- statement: + - keyword: RENAME + - keyword: TABLE + - table_reference: + - naked_identifier: old_table1 + - keyword: TO + - table_reference: + - naked_identifier: new_table1 + - comma: ',' + - table_reference: + - naked_identifier: old_table2 + - keyword: TO + - table_reference: + - naked_identifier: new_table2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/repair_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/repair_table.sql new file mode 100644 index 000000000..2ab1bd49a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/repair_table.sql @@ -0,0 +1,19 @@ +REPAIR TABLE some_table; + +REPAIR TABLE some_table1, some_table2; + +REPAIR NO_WRITE_TO_BINLOG TABLE some_table; + +REPAIR NO_WRITE_TO_BINLOG TABLE some_table1, some_table2; + +REPAIR LOCAL TABLE some_table; + +REPAIR LOCAL TABLE some_table1, some_table2; + +REPAIR TABLE some_table QUICK; + +REPAIR TABLE some_table EXTENDED; + +REPAIR TABLE some_table USE_FRM; + +REPAIR TABLE some_table QUICK EXTENDED USE_FRM; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/repair_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/repair_table.yml new file mode 100644 index 000000000..44fa674f5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/repair_table.yml @@ -0,0 +1,80 @@ +file: +- statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - keyword: REPAIR + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - keyword: REPAIR + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - keyword: REPAIR + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - keyword: REPAIR + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: QUICK +- statement_terminator: ; +- statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: EXTENDED +- statement_terminator: ; +- statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: USE_FRM +- statement_terminator: ; +- statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: QUICK + - keyword: EXTENDED + - keyword: USE_FRM +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_label.sql new file mode 100644 index 000000000..b39b29ee9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_label.sql @@ -0,0 +1 @@ +iteration:repeat set @a = @a + 1; until @a > 5 end repeat iteration; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_label.yml new file mode 100644 index 000000000..e69118519 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_label.yml @@ -0,0 +1,7 @@ +file: +- statement: + - naked_identifier: iteration + - colon: ':' + - keyword: repeat +- file: + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_multiple_statements.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_multiple_statements.sql new file mode 100644 index 000000000..9cabce05b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_multiple_statements.sql @@ -0,0 +1 @@ +repeat set @a = @a + 1; select 1; until @a > 5 and x = 1 end repeat; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_multiple_statements.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_multiple_statements.yml new file mode 100644 index 000000000..85d4b8c7d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_multiple_statements.yml @@ -0,0 +1,5 @@ +file: +- statement: + - keyword: repeat +- file: + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_no_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_no_label.sql new file mode 100644 index 000000000..59a34c8fe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_no_label.sql @@ -0,0 +1 @@ +repeat set @a = @a + 1; until @a > 5 end repeat; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_no_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_no_label.yml new file mode 100644 index 000000000..85d4b8c7d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/repeat_no_label.yml @@ -0,0 +1,5 @@ +file: +- statement: + - keyword: repeat +- file: + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/replace.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/replace.sql new file mode 100644 index 000000000..b5d84110f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/replace.sql @@ -0,0 +1,43 @@ +REPLACE tbl_name VALUES (1, 2); + +REPLACE tbl_name VALUES (DEFAULT, DEFAULT); + +REPLACE tbl_name VALUES (1, 2), (11, 22); + +REPLACE tbl_name VALUE (1, 2), (11, 22); + +REPLACE tbl_name (col1, col2) VALUES (1, 2); + +REPLACE tbl_name (col1, col2) VALUES ROW(1, 2), ROW(11, 22); + +REPLACE LOW_PRIORITY tbl_name VALUES (1, 2); + +REPLACE DELAYED tbl_name VALUES (1, 2); + +REPLACE LOW_PRIORITY INTO tbl_name VALUES (1, 2); + +REPLACE tbl_name PARTITION (partition_name) VALUES (1, 2); + +REPLACE tbl_name SET col1 = 1, col2 = 2; + +REPLACE LOW_PRIORITY tbl_name SET col1 = 1, col2 = 2; + +REPLACE DELAYED tbl_name SET col1 = 1, col2 = 2; + +REPLACE LOW_PRIORITY INTO tbl_name SET col1 = 1, col2 = 2; + +REPLACE tbl_name PARTITION (partition_name) SET col1 = 1, col2 = 2; + +REPLACE tbl_name SELECT * FROM table_name; + +REPLACE tbl_name TABLE table_name; + +REPLACE LOW_PRIORITY tbl_name TABLE table_name; + +REPLACE DELAYED tbl_name TABLE table_name; + +REPLACE LOW_PRIORITY INTO tbl_name TABLE table_name; + +REPLACE tbl_name (col1, col2) TABLE table_name; + +REPLACE tbl_name PARTITION (partition_name) TABLE table_name; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/replace.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/replace.yml new file mode 100644 index 000000000..3a214e2f9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/replace.yml @@ -0,0 +1,375 @@ +file: +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - keyword: DEFAULT + - comma: ',' + - keyword: DEFAULT + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - comma: ',' + - numeric_literal: '22' + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUE + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - comma: ',' + - numeric_literal: '22' + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - values_clause: + - keyword: VALUES + - keyword: ROW + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - keyword: ROW + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - comma: ',' + - numeric_literal: '22' + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: REPLACE + - keyword: DELAYED + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - keyword: INTO + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: partition_name + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - table_reference: + - naked_identifier: tbl_name + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - keyword: REPLACE + - keyword: DELAYED + - table_reference: + - naked_identifier: tbl_name + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - keyword: INTO + - table_reference: + - naked_identifier: tbl_name + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: partition_name + - end_bracket: ) + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - table_reference: + - naked_identifier: tbl_name + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - keyword: REPLACE + - keyword: DELAYED + - table_reference: + - naked_identifier: tbl_name + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - keyword: INTO + - table_reference: + - naked_identifier: tbl_name + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: partition_name + - end_bracket: ) + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/reset_master.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/reset_master.sql new file mode 100644 index 000000000..90358cd74 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/reset_master.sql @@ -0,0 +1,2 @@ +RESET MASTER; +RESET MASTER TO 1234; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/reset_master.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/reset_master.yml new file mode 100644 index 000000000..133a6e560 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/reset_master.yml @@ -0,0 +1,11 @@ +file: +- statement: + - keyword: RESET + - keyword: MASTER +- statement_terminator: ; +- statement: + - keyword: RESET + - keyword: MASTER + - keyword: TO + - numeric_literal: '1234' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal.sql new file mode 100644 index 000000000..c838afd76 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal.sql @@ -0,0 +1 @@ +resignal; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal.yml new file mode 100644 index 000000000..61a7aaec2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal.yml @@ -0,0 +1,4 @@ +file: +- statement: + - keyword: resignal +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_name.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_name.sql new file mode 100644 index 000000000..008d08510 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_name.sql @@ -0,0 +1 @@ +resignal testcondition; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_name.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_name.yml new file mode 100644 index 000000000..7de0f01a1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_name.yml @@ -0,0 +1,5 @@ +file: +- statement: + - keyword: resignal + - naked_identifier: testcondition +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate.sql new file mode 100644 index 000000000..b4372c824 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate.sql @@ -0,0 +1 @@ +resignal sqlstate '42S02'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate.yml new file mode 100644 index 000000000..5e3073585 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate.yml @@ -0,0 +1,6 @@ +file: +- statement: + - keyword: resignal + - keyword: sqlstate + - quoted_literal: '''42S02''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate_value.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate_value.sql new file mode 100644 index 000000000..0d12b18c9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate_value.sql @@ -0,0 +1 @@ +resignal sqlstate value '42S02'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate_value.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate_value.yml new file mode 100644 index 000000000..d6e2077fc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_condition_sqlstate_value.yml @@ -0,0 +1,7 @@ +file: +- statement: + - keyword: resignal + - keyword: sqlstate + - keyword: value + - quoted_literal: '''42S02''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info.sql new file mode 100644 index 000000000..05c921a9e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info.sql @@ -0,0 +1 @@ +resignal set message_text = 'test message'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info.yml new file mode 100644 index 000000000..3f4d99f51 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info.yml @@ -0,0 +1,9 @@ +file: +- statement: + - keyword: resignal + - keyword: set + - keyword: message_text + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test message''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info_multiple.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info_multiple.sql new file mode 100644 index 000000000..e5d4856d1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info_multiple.sql @@ -0,0 +1 @@ +resignal set message_text = 'test message', mysql_errno = '42S500'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info_multiple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info_multiple.yml new file mode 100644 index 000000000..4acc1b6ee --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/resignal_set_signal_info_multiple.yml @@ -0,0 +1,14 @@ +file: +- statement: + - keyword: resignal + - keyword: set + - keyword: message_text + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test message''' + - comma: ',' + - keyword: mysql_errno + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''42S500''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_distinctrow.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_distinctrow.sql new file mode 100644 index 000000000..db2026f18 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_distinctrow.sql @@ -0,0 +1 @@ +select distinctrow * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_distinctrow.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_distinctrow.yml new file mode 100644 index 000000000..dcc86e030 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_distinctrow.yml @@ -0,0 +1,16 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - unparsable: + - word: distinctrow + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_share.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_share.sql new file mode 100644 index 000000000..7c51735c7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_share.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR SHARE; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_share.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_share.yml new file mode 100644 index 000000000..8f586209e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_share.yml @@ -0,0 +1,18 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - unparsable: + - word: FOR + - word: SHARE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update.sql new file mode 100644 index 000000000..c2d4baa1b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR UPDATE; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update.yml new file mode 100644 index 000000000..88ec8cb6c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update.yml @@ -0,0 +1,18 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - unparsable: + - word: FOR + - word: UPDATE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_lock_in_share_mode.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_lock_in_share_mode.sql new file mode 100644 index 000000000..146c81e51 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_lock_in_share_mode.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 LOCK IN SHARE MODE; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_lock_in_share_mode.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_lock_in_share_mode.yml new file mode 100644 index 000000000..039ea45b8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_lock_in_share_mode.yml @@ -0,0 +1,20 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - unparsable: + - word: LOCK + - word: IN + - word: SHARE + - word: MODE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_nowait.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_nowait.sql new file mode 100644 index 000000000..e33fb9a0e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_nowait.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR UPDATE NOWAIT; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_nowait.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_nowait.yml new file mode 100644 index 000000000..3dff41666 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_nowait.yml @@ -0,0 +1,19 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - unparsable: + - word: FOR + - word: UPDATE + - word: NOWAIT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of.sql new file mode 100644 index 000000000..25cf21ed4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR UPDATE OF test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of.yml new file mode 100644 index 000000000..56a4e7789 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of.yml @@ -0,0 +1,20 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - unparsable: + - word: FOR + - word: UPDATE + - word: OF + - word: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of_multiple.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of_multiple.sql new file mode 100644 index 000000000..3af55ca2a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of_multiple.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR UPDATE OF test1, test2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of_multiple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of_multiple.yml new file mode 100644 index 000000000..75d5bdcf6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_of_multiple.yml @@ -0,0 +1,22 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - unparsable: + - word: FOR + - word: UPDATE + - word: OF + - word: test1 + - comma: ',' + - word: test2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_skip_locked.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_skip_locked.sql new file mode 100644 index 000000000..e01f3b0e4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_skip_locked.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR UPDATE SKIP LOCKED; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_skip_locked.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_skip_locked.yml new file mode 100644 index 000000000..bc660c3a3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_for_update_skip_locked.yml @@ -0,0 +1,20 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - unparsable: + - word: FOR + - word: UPDATE + - word: SKIP + - word: LOCKED +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_high_priority.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_high_priority.sql new file mode 100644 index 000000000..89acded8c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_high_priority.sql @@ -0,0 +1 @@ +select HIGH_PRIORITY * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_high_priority.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_high_priority.yml new file mode 100644 index 000000000..f40440c4b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_high_priority.yml @@ -0,0 +1,16 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - unparsable: + - word: HIGH_PRIORITY + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_dumpfile.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_dumpfile.sql new file mode 100644 index 000000000..73e0e573a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_dumpfile.sql @@ -0,0 +1 @@ +select * into dumpfile '' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_dumpfile.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_dumpfile.yml new file mode 100644 index 000000000..537aafad5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_dumpfile.yml @@ -0,0 +1,21 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - unparsable: + - word: into + - word: dumpfile + - single_quote: '''''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_multiple_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_multiple_variable.sql new file mode 100644 index 000000000..170faa1ab --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_multiple_variable.sql @@ -0,0 +1 @@ +select 1, @test2, _test3, 'test4', func(test5) into @test1, @test2, _test3, @test4, @test5 from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_multiple_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_multiple_variable.yml new file mode 100644 index 000000000..209757f98 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_multiple_variable.yml @@ -0,0 +1,8 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' + - comma: ',' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile.sql new file mode 100644 index 000000000..eaff0b2bb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile.sql @@ -0,0 +1 @@ +select * into outfile 'a' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile.yml new file mode 100644 index 000000000..be4015f7e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile.yml @@ -0,0 +1,21 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - unparsable: + - word: into + - word: outfile + - single_quote: '''a''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_enclosed.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_enclosed.sql new file mode 100644 index 000000000..70b22b0f3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_enclosed.sql @@ -0,0 +1 @@ +select * into outfile 'a' fields enclosed by '"' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_enclosed.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_enclosed.yml new file mode 100644 index 000000000..74389d2b8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_enclosed.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - unparsable: + - word: into + - word: outfile + - single_quote: '''a''' + - word: fields + - word: enclosed + - word: by + - single_quote: '''"''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_escaped.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_escaped.sql new file mode 100644 index 000000000..3736331c1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_escaped.sql @@ -0,0 +1 @@ +select * into outfile 'a' fields escaped by '-' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_escaped.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_escaped.yml new file mode 100644 index 000000000..35306acd1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_escaped.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - unparsable: + - word: into + - word: outfile + - single_quote: '''a''' + - word: fields + - word: escaped + - word: by + - single_quote: '''-''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_optionally_enclosed.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_optionally_enclosed.sql new file mode 100644 index 000000000..966087e4d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_optionally_enclosed.sql @@ -0,0 +1 @@ +select * into outfile 'a' fields optionally enclosed by '"' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_optionally_enclosed.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_optionally_enclosed.yml new file mode 100644 index 000000000..6f9e25e51 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_optionally_enclosed.yml @@ -0,0 +1,26 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - unparsable: + - word: into + - word: outfile + - single_quote: '''a''' + - word: fields + - word: optionally + - word: enclosed + - word: by + - single_quote: '''"''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_terminated.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_terminated.sql new file mode 100644 index 000000000..5011ef419 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_terminated.sql @@ -0,0 +1 @@ +select * into outfile 'a' fields terminated by '"' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_terminated.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_terminated.yml new file mode 100644 index 000000000..57cd6fa9f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_fields_terminated.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - unparsable: + - word: into + - word: outfile + - single_quote: '''a''' + - word: fields + - word: terminated + - word: by + - single_quote: '''"''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_starting.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_starting.sql new file mode 100644 index 000000000..85425ce94 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_starting.sql @@ -0,0 +1 @@ +select * into outfile 'a' lines starting by '\n' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_starting.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_starting.yml new file mode 100644 index 000000000..70bc328fd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_starting.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - unparsable: + - word: into + - word: outfile + - single_quote: '''a''' + - word: lines + - word: starting + - word: by + - single_quote: '''\n''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_terminated.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_terminated.sql new file mode 100644 index 000000000..27d3a1a2b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_terminated.sql @@ -0,0 +1 @@ +select * into outfile 'a' lines terminated by '\n' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_terminated.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_terminated.yml new file mode 100644 index 000000000..a0eb196ba --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_outfile_lines_terminated.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - unparsable: + - word: into + - word: outfile + - single_quote: '''a''' + - word: lines + - word: terminated + - word: by + - single_quote: '''\n''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_session_variable.sql new file mode 100644 index 000000000..5e898e760 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_session_variable.sql @@ -0,0 +1,11 @@ +select 1 into @dumpfile from table1; + +SELECT name +INTO @name +FROM t +WHERE id = 1; + +SELECT name +FROM t +WHERE id = 1 +INTO @name; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_session_variable.yml new file mode 100644 index 000000000..2c9f86614 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_into_session_variable.yml @@ -0,0 +1,9 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' + - unparsable: + - word: into diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_local_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_local_variable.sql new file mode 100644 index 000000000..62687e034 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_local_variable.sql @@ -0,0 +1 @@ +select test2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_local_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_local_variable.yml new file mode 100644 index 000000000..4c270691c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_local_variable.yml @@ -0,0 +1,9 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: test2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_lock_in_share_mode.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_lock_in_share_mode.sql new file mode 100644 index 000000000..bbe8996ff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_lock_in_share_mode.sql @@ -0,0 +1 @@ +select 1 from table1 lock in share mode; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_lock_in_share_mode.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_lock_in_share_mode.yml new file mode 100644 index 000000000..84ba9bbfb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_lock_in_share_mode.yml @@ -0,0 +1,20 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - unparsable: + - word: lock + - word: in + - word: share + - word: mode +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_multiple_partition.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_multiple_partition.sql new file mode 100644 index 000000000..bb08982bb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_multiple_partition.sql @@ -0,0 +1 @@ +select * from table1 PARTITION(part1, part2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_multiple_partition.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_multiple_partition.yml new file mode 100644 index 000000000..28fcdbe2b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_multiple_partition.yml @@ -0,0 +1,24 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - unparsable: + - word: PARTITION + - start_bracket: ( + - word: part1 + - comma: ',' + - word: part2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_operators.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_operators.sql new file mode 100644 index 000000000..b68e189e3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_operators.sql @@ -0,0 +1,9 @@ +SELECT !1; +SELECT 1 && 1; +SELECT 1 && 0; +SELECT 1 XOR 1; +SELECT 1 || 1; +SELECT col_1 && 1; +SELECT (col_1 = col_2) || col_3; +SELECT 5 DIV 2; +SELECT 5 MOD 2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_operators.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_operators.yml new file mode 100644 index 000000000..d1983339c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_operators.yml @@ -0,0 +1,107 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - unparsable: + - raw_comparison_operator: '!' + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - unparsable: + - ampersand: '&' + - ampersand: '&' + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - unparsable: + - ampersand: '&' + - ampersand: '&' + - numeric_literal: '0' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - unparsable: + - word: XOR + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: + - pipe: '|' + - pipe: '|' + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col_1 + - unparsable: + - ampersand: '&' + - ampersand: '&' + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col_1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: col_2 + - end_bracket: ) + - binary_operator: + - pipe: '|' + - pipe: '|' + - column_reference: + - naked_identifier: col_3 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '5' + - unparsable: + - word: DIV + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '5' + - unparsable: + - word: MOD + - numeric_literal: '2' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_partition.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_partition.sql new file mode 100644 index 000000000..88f312fcf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_partition.sql @@ -0,0 +1 @@ +select * from table1 PARTITION(part1); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_partition.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_partition.yml new file mode 100644 index 000000000..f2169e368 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_partition.yml @@ -0,0 +1,22 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - unparsable: + - word: PARTITION + - start_bracket: ( + - word: part1 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_session_variable.sql new file mode 100644 index 000000000..b3eb25596 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_session_variable.sql @@ -0,0 +1 @@ +select @test2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_session_variable.yml new file mode 100644 index 000000000..8225ef63c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_session_variable.yml @@ -0,0 +1,6 @@ +file: +- statement: + - select_statement: + - select_clause: + - unparsable: + - keyword: select diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_big_result.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_big_result.sql new file mode 100644 index 000000000..5f5b37ccf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_big_result.sql @@ -0,0 +1 @@ +select SQL_BIG_RESULT * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_big_result.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_big_result.yml new file mode 100644 index 000000000..0fba81aae --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_big_result.yml @@ -0,0 +1,16 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - unparsable: + - word: SQL_BIG_RESULT + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_buffer_result.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_buffer_result.sql new file mode 100644 index 000000000..e2506a9ae --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_buffer_result.sql @@ -0,0 +1 @@ +select SQL_BUFFER_RESULT * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_buffer_result.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_buffer_result.yml new file mode 100644 index 000000000..3d8548326 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_buffer_result.yml @@ -0,0 +1,18 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: SQL_BUFFER_RESULT + - unparsable: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_cache.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_cache.sql new file mode 100644 index 000000000..7e9e3aa7d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_cache.sql @@ -0,0 +1 @@ +select SQL_CACHE * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_cache.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_cache.yml new file mode 100644 index 000000000..ebae463a8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_cache.yml @@ -0,0 +1,18 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: SQL_CACHE + - unparsable: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_calc_found_rows.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_calc_found_rows.sql new file mode 100644 index 000000000..8ad75e08f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_calc_found_rows.sql @@ -0,0 +1 @@ +select SQL_CALC_FOUND_ROWS * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_calc_found_rows.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_calc_found_rows.yml new file mode 100644 index 000000000..9cea754f7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_calc_found_rows.yml @@ -0,0 +1,16 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - unparsable: + - word: SQL_CALC_FOUND_ROWS + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_no_cache.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_no_cache.sql new file mode 100644 index 000000000..4640f417d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_no_cache.sql @@ -0,0 +1 @@ +select SQL_NO_CACHE * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_no_cache.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_no_cache.yml new file mode 100644 index 000000000..0345e3f24 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_no_cache.yml @@ -0,0 +1,18 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: SQL_NO_CACHE + - unparsable: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_small_result.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_small_result.sql new file mode 100644 index 000000000..dece227f3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_small_result.sql @@ -0,0 +1 @@ +select SQL_SMALL_RESULT * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_small_result.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_small_result.yml new file mode 100644 index 000000000..caa22d600 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_sql_small_result.yml @@ -0,0 +1,16 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - unparsable: + - word: SQL_SMALL_RESULT + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_straight_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_straight_join.sql new file mode 100644 index 000000000..fa5a25ccd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_straight_join.sql @@ -0,0 +1 @@ +select STRAIGHT_JOIN * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_straight_join.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_straight_join.yml new file mode 100644 index 000000000..674df97cc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_straight_join.yml @@ -0,0 +1,16 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - unparsable: + - word: STRAIGHT_JOIN + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_date_part_function.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_date_part_function.sql new file mode 100644 index 000000000..c8f39ff08 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_date_part_function.sql @@ -0,0 +1,7 @@ +SELECT EXTRACT(YEAR FROM '2019-07-02'); +SELECT TIMESTAMPADD(MINUTE, 1, '2003-01-02'); +SELECT TIMESTAMPDIFF(MONTH, '2003-02-01', '2003-05-01'); +SELECT TIMESTAMPDIFF(HOUR, x.time_created, x.time_updated) +FROM example_table AS x; +SELECT TIMESTAMPADD(SECOND, 1, x.some_timestamp_field) +FROM example_table AS x; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_date_part_function.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_date_part_function.yml new file mode 100644 index 000000000..b2be1ed76 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_date_part_function.yml @@ -0,0 +1,120 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: EXTRACT + - bracketed: + - start_bracket: ( + - date_part: YEAR + - keyword: FROM + - expression: + - quoted_literal: '''2019-07-02''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: TIMESTAMPADD + - bracketed: + - start_bracket: ( + - date_part: MINUTE + - comma: ',' + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - quoted_literal: '''2003-01-02''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: TIMESTAMPDIFF + - bracketed: + - start_bracket: ( + - date_part: MONTH + - comma: ',' + - expression: + - quoted_literal: '''2003-02-01''' + - comma: ',' + - expression: + - quoted_literal: '''2003-05-01''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: TIMESTAMPDIFF + - bracketed: + - start_bracket: ( + - date_part: HOUR + - comma: ',' + - expression: + - column_reference: + - naked_identifier: x + - dot: . + - naked_identifier: time_created + - comma: ',' + - expression: + - column_reference: + - naked_identifier: x + - dot: . + - naked_identifier: time_updated + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: example_table + - keyword: AS + - naked_identifier: x +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: TIMESTAMPADD + - bracketed: + - start_bracket: ( + - date_part: SECOND + - comma: ',' + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: x + - dot: . + - naked_identifier: some_timestamp_field + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: example_table + - keyword: AS + - naked_identifier: x +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_regexp.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_regexp.sql new file mode 100644 index 000000000..e00130dd7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_regexp.sql @@ -0,0 +1,3 @@ +SELECT * +FROM `db`.tbl +WHERE col REGEXP '^[0-9]*$' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_regexp.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_regexp.yml new file mode 100644 index 000000000..a8df23b40 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/select_with_regexp.yml @@ -0,0 +1,18 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - unparsable: + - word: FROM + - back_quote: '`db`' + - dot: . + - word: tbl + - word: WHERE + - word: col + - word: REGEXP + - single_quote: '''^[0-9]*$''' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_booleans.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/set_booleans.sql new file mode 100644 index 000000000..c99061cde --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_booleans.sql @@ -0,0 +1,6 @@ +SET some_bool_param = ON; +SET some_bool_param = OFF; +SET some_bool_param = TRUE; +SET some_bool_param = FALSE; +SET some_bool_param = 0; +SET some_bool_param = 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_booleans.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/set_booleans.yml new file mode 100644 index 000000000..f7fb13746 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_booleans.yml @@ -0,0 +1,49 @@ +file: +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - keyword: 'TRUE' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - keyword: 'FALSE' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - variable: '0' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - variable: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_multiple_variables.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/set_multiple_variables.sql new file mode 100644 index 000000000..735bfa65f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_multiple_variables.sql @@ -0,0 +1 @@ +SET a = 1, b = 2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_multiple_variables.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/set_multiple_variables.yml new file mode 100644 index 000000000..f063f44e8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_multiple_variables.yml @@ -0,0 +1,14 @@ +file: +- statement: + - set_statement: + - keyword: SET + - variable: a + - comparison_operator: + - raw_comparison_operator: = + - variable: '1' + - comma: ',' + - variable: b + - comparison_operator: + - raw_comparison_operator: = + - variable: '2' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_names.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/set_names.sql new file mode 100644 index 000000000..e06172661 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_names.sql @@ -0,0 +1,11 @@ +SET NAMES utf8mb4; + +SET NAMES 'utf8'; + +SET NAMES DEFAULT; + +SET NAMES ascii COLLATE ascii_bin; + +SET NAMES 'ascii' COLLATE 'ascii_bin'; + +SET NAMES ascii COLLATE 'ascii_bin'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_names.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/set_names.yml new file mode 100644 index 000000000..4a285e271 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_names.yml @@ -0,0 +1,40 @@ +file: +- statement: + - keyword: SET + - keyword: NAMES + - naked_identifier: utf8mb4 +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: NAMES + - quoted_literal: '''utf8''' +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: NAMES + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: NAMES + - naked_identifier: ascii + - keyword: COLLATE + - collation_reference: + - naked_identifier: ascii_bin +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: NAMES + - quoted_literal: '''ascii''' + - keyword: COLLATE + - collation_reference: + - quoted_literal: '''ascii_bin''' +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: NAMES + - naked_identifier: ascii + - keyword: COLLATE + - collation_reference: + - quoted_literal: '''ascii_bin''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable.sql new file mode 100644 index 000000000..8c864cb88 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable.sql @@ -0,0 +1,4 @@ +set @abc = 1; +set @my_var = 1; +set @my$currency = 1; +set @sha256enabled = 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable.yml new file mode 100644 index 000000000..51b421a66 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable.yml @@ -0,0 +1,3 @@ +file: +- unparsable: + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable_expression.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable_expression.sql new file mode 100644 index 000000000..b35b2d7a5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable_expression.sql @@ -0,0 +1,3 @@ +set @abc = 1 + 2; +set @abc = (select 1); +SET @id = (SELECT id FROM table1 WHERE field = TRUE LIMIT 1); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable_expression.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable_expression.yml new file mode 100644 index 000000000..51b421a66 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_session_variable_expression.yml @@ -0,0 +1,3 @@ +file: +- unparsable: + - word: set diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_sql_log_bin.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/set_sql_log_bin.sql new file mode 100644 index 000000000..49c9d39e5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_sql_log_bin.sql @@ -0,0 +1,2 @@ +SET sql_log_bin = ON; +SET sql_log_bin = OFF; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_sql_log_bin.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/set_sql_log_bin.yml new file mode 100644 index 000000000..526b8bcef --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_sql_log_bin.yml @@ -0,0 +1,17 @@ +file: +- statement: + - set_statement: + - keyword: SET + - variable: sql_log_bin + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: sql_log_bin + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_system_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/set_system_variable.sql new file mode 100644 index 000000000..30c74d8e0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_system_variable.sql @@ -0,0 +1,3 @@ +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_system_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/set_system_variable.yml new file mode 100644 index 000000000..a129507c1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_system_variable.yml @@ -0,0 +1,3 @@ +file: +- unparsable: + - word: SET diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_transaction.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/set_transaction.sql new file mode 100644 index 000000000..32056fa5a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_transaction.sql @@ -0,0 +1,12 @@ +SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; +SET TRANSACTION ISOLATION LEVEL READ COMMITTED; +SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; +SET GLOBAL TRANSACTION ISOLATION LEVEL REPEATABLE READ; +SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; +SET TRANSACTION READ WRITE; +SET GLOBAL TRANSACTION READ ONLY; +SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ ONLY; +SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE; +SET SESSION TRANSACTION READ WRITE, ISOLATION LEVEL READ UNCOMMITTED; +SET TRANSACTION READ ONLY, ISOLATION LEVEL SERIALIZABLE; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/set_transaction.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/set_transaction.yml new file mode 100644 index 000000000..41776f6ba --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/set_transaction.yml @@ -0,0 +1,108 @@ +file: +- statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: REPEATABLE + - keyword: READ +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: READ + - keyword: COMMITTED +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: READ + - keyword: UNCOMMITTED +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: SERIALIZABLE +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: GLOBAL + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: REPEATABLE + - keyword: READ +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: SESSION + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: READ + - keyword: COMMITTED +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: READ + - keyword: WRITE +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: GLOBAL + - keyword: TRANSACTION + - keyword: READ + - keyword: ONLY +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: SESSION + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: REPEATABLE + - keyword: READ + - comma: ',' + - keyword: READ + - keyword: ONLY +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: GLOBAL + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: SERIALIZABLE + - comma: ',' + - keyword: READ + - keyword: WRITE +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: SESSION + - keyword: TRANSACTION + - keyword: READ + - keyword: WRITE + - comma: ',' + - keyword: ISOLATION + - keyword: LEVEL + - keyword: READ + - keyword: UNCOMMITTED +- statement_terminator: ; +- statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: READ + - keyword: ONLY + - comma: ',' + - keyword: ISOLATION + - keyword: LEVEL + - keyword: SERIALIZABLE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/signal.sql new file mode 100644 index 000000000..c838afd76 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal.sql @@ -0,0 +1 @@ +resignal; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/signal.yml new file mode 100644 index 000000000..61a7aaec2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal.yml @@ -0,0 +1,4 @@ +file: +- statement: + - keyword: resignal +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_name.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_name.sql new file mode 100644 index 000000000..008d08510 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_name.sql @@ -0,0 +1 @@ +resignal testcondition; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_name.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_name.yml new file mode 100644 index 000000000..7de0f01a1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_name.yml @@ -0,0 +1,5 @@ +file: +- statement: + - keyword: resignal + - naked_identifier: testcondition +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate.sql new file mode 100644 index 000000000..b4372c824 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate.sql @@ -0,0 +1 @@ +resignal sqlstate '42S02'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate.yml new file mode 100644 index 000000000..5e3073585 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate.yml @@ -0,0 +1,6 @@ +file: +- statement: + - keyword: resignal + - keyword: sqlstate + - quoted_literal: '''42S02''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate_value.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate_value.sql new file mode 100644 index 000000000..0d12b18c9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate_value.sql @@ -0,0 +1 @@ +resignal sqlstate value '42S02'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate_value.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate_value.yml new file mode 100644 index 000000000..d6e2077fc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_condition_sqlstate_value.yml @@ -0,0 +1,7 @@ +file: +- statement: + - keyword: resignal + - keyword: sqlstate + - keyword: value + - quoted_literal: '''42S02''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info.sql new file mode 100644 index 000000000..05c921a9e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info.sql @@ -0,0 +1 @@ +resignal set message_text = 'test message'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info.yml new file mode 100644 index 000000000..3f4d99f51 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info.yml @@ -0,0 +1,9 @@ +file: +- statement: + - keyword: resignal + - keyword: set + - keyword: message_text + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test message''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info_multiple.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info_multiple.sql new file mode 100644 index 000000000..e5d4856d1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info_multiple.sql @@ -0,0 +1 @@ +resignal set message_text = 'test message', mysql_errno = '42S500'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info_multiple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info_multiple.yml new file mode 100644 index 000000000..4acc1b6ee --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/signal_set_signal_info_multiple.yml @@ -0,0 +1,14 @@ +file: +- statement: + - keyword: resignal + - keyword: set + - keyword: message_text + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test message''' + - comma: ',' + - keyword: mysql_errno + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''42S500''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/system_variables.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/system_variables.sql new file mode 100644 index 000000000..ff86cb2ff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/system_variables.sql @@ -0,0 +1,5 @@ +SELECT @@global.time_zone; +SELECT @@session.time_zone; +SELECT @@global.version; +SELECT @@session.rand_seed1; +SELECT CONVERT_TZ(NOW(), @@global.time_zone, '+00:00') diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/system_variables.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/system_variables.yml new file mode 100644 index 000000000..2af97a140 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/system_variables.yml @@ -0,0 +1,6 @@ +file: +- statement: + - select_statement: + - select_clause: + - unparsable: + - keyword: SELECT diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/update.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/update.sql new file mode 100644 index 000000000..92e540781 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/update.sql @@ -0,0 +1,39 @@ +UPDATE t1 SET col1 = col1 + 1; + +UPDATE t1 SET col1 = col1 + 1, col2 = col1; + +UPDATE items,month SET items.price=month.price +WHERE items.id=month.id; + +UPDATE t SET id = id + 1 ORDER BY id DESC; + +UPDATE items +SET retail = retail * 0.9 +WHERE id IN +(SELECT id FROM items +WHERE retail / wholesale >= 1.3 AND quantity > 100); + +UPDATE items, + (SELECT id FROM items + WHERE id IN + (SELECT id FROM items + WHERE retail / wholesale >= 1.3 AND quantity < 100)) + AS discounted +SET items.retail = items.retail * 0.9 +WHERE items.id = discounted.id; + +UPDATE items, + (SELECT id, retail / wholesale AS markup, quantity FROM items) + AS discounted + SET items.retail = items.retail * 0.9 + WHERE discounted.markup >= 1.3 + AND discounted.quantity < 100 + AND items.id = discounted.id; + +UPDATE LOW_PRIORITY foo +SET bar = 7 +LIMIT 4; + +UPDATE a, b SET a.name = b.name WHERE a.id = b.id; + +UPDATE a join b on a.id = b.id set a.type = b.type where a.type is null; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/update.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/update.yml new file mode 100644 index 000000000..e025f24ec --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/update.yml @@ -0,0 +1,440 @@ +file: +- statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: t1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: col1 + - binary_operator: + + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: t1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: col1 + - binary_operator: + + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: col1 +- statement_terminator: ; +- statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: items + - comma: ',' + - table_reference: + - naked_identifier: month + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: price + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: month + - dot: . + - naked_identifier: price + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: month + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: t + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: id + - binary_operator: + + - numeric_literal: '1' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: id + - keyword: DESC +- statement_terminator: ; +- statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: items + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: retail + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: retail + - binary_operator: '*' + - numeric_literal: '0.9' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: id + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: retail + - binary_operator: / + - column_reference: + - naked_identifier: wholesale + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - numeric_literal: '1.3' + - binary_operator: AND + - column_reference: + - naked_identifier: quantity + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '100' + - end_bracket: ) +- statement_terminator: ; +- statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: items + - comma: ',' + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: id + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: retail + - binary_operator: / + - column_reference: + - naked_identifier: wholesale + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - numeric_literal: '1.3' + - binary_operator: AND + - column_reference: + - naked_identifier: quantity + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '100' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - naked_identifier: discounted + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: retail + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: retail + - binary_operator: '*' + - numeric_literal: '0.9' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: discounted + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: items + - comma: ',' + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: retail + - binary_operator: / + - column_reference: + - naked_identifier: wholesale + - keyword: AS + - naked_identifier: markup + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: quantity + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - end_bracket: ) + - keyword: AS + - naked_identifier: discounted + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: retail + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: retail + - binary_operator: '*' + - numeric_literal: '0.9' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: discounted + - dot: . + - naked_identifier: markup + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - numeric_literal: '1.3' + - binary_operator: AND + - column_reference: + - naked_identifier: discounted + - dot: . + - naked_identifier: quantity + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '100' + - binary_operator: AND + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: discounted + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - keyword: UPDATE + - keyword: LOW_PRIORITY + - table_reference: + - naked_identifier: foo + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: bar + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '7' + - limit_clause: + - keyword: LIMIT + - numeric_literal: '4' +- statement_terminator: ; +- statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: a + - comma: ',' + - table_reference: + - naked_identifier: b + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: name + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - keyword: UPDATE + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: a + - join_clause: + - keyword: join + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: b + - join_on_condition: + - keyword: on + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: id + - set_clause_list: + - keyword: set + - set_clause: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: type + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: type + - where_clause: + - keyword: where + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: type + - keyword: is + - null_literal: 'null' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_database.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/use_database.sql new file mode 100644 index 000000000..256e8e47e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_database.sql @@ -0,0 +1 @@ +use my_db; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_database.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/use_database.yml new file mode 100644 index 000000000..a6db23ca2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_database.yml @@ -0,0 +1,7 @@ +file: +- statement: + - use_statement: + - keyword: use + - database_reference: + - naked_identifier: my_db +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index.sql new file mode 100644 index 000000000..282152b59 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index.sql @@ -0,0 +1 @@ +SELECT * FROM t1 test USE INDEX (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_index.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index.yml new file mode 100644 index 000000000..ffebfb404 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index.yml @@ -0,0 +1,24 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - naked_identifier: test + - unparsable: + - word: USE + - word: INDEX + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_group_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_group_by.sql new file mode 100644 index 000000000..0df246fee --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_group_by.sql @@ -0,0 +1 @@ +SELECT * FROM t1 test USE INDEX FOR GROUP BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_group_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_group_by.yml new file mode 100644 index 000000000..820aa1a19 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_group_by.yml @@ -0,0 +1,27 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - naked_identifier: test + - unparsable: + - word: USE + - word: INDEX + - word: FOR + - word: GROUP + - word: BY + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_join.sql new file mode 100644 index 000000000..923048b53 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_join.sql @@ -0,0 +1 @@ +SELECT * FROM t1 test USE INDEX FOR JOIN (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_join.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_join.yml new file mode 100644 index 000000000..25a110780 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_join.yml @@ -0,0 +1,26 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - naked_identifier: test + - unparsable: + - word: USE + - word: INDEX + - word: FOR + - word: JOIN + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_order_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_order_by.sql new file mode 100644 index 000000000..33b7ae47f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_order_by.sql @@ -0,0 +1 @@ +SELECT * FROM t1 test USE INDEX FOR ORDER BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_order_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_order_by.yml new file mode 100644 index 000000000..8741a468c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_index_for_order_by.yml @@ -0,0 +1,27 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - naked_identifier: test + - unparsable: + - word: USE + - word: INDEX + - word: FOR + - word: ORDER + - word: BY + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_key.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/use_key.sql new file mode 100644 index 000000000..d034b5a7c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_key.sql @@ -0,0 +1 @@ +SELECT * FROM t1 test USE KEY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_key.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/use_key.yml new file mode 100644 index 000000000..25fa6694f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_key.yml @@ -0,0 +1,24 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - naked_identifier: test + - unparsable: + - word: USE + - word: KEY + - start_bracket: ( + - word: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_statement.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/use_statement.sql new file mode 100644 index 000000000..610507790 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_statement.sql @@ -0,0 +1 @@ +USE db; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/use_statement.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/use_statement.yml new file mode 100644 index 000000000..530b518e1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/use_statement.yml @@ -0,0 +1,7 @@ +file: +- statement: + - use_statement: + - keyword: USE + - database_reference: + - naked_identifier: db +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/values_statement.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/values_statement.sql new file mode 100644 index 000000000..b3e547f46 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/values_statement.sql @@ -0,0 +1,5 @@ +VALUES ROW ('a', 1), ROW ('b', 2); + +VALUES ROW ('a', 1), ROW (upper('b'), 2+1); + +VALUES ROW (CURRENT_DATE, '2020-06-04' + interval -5 day); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/values_statement.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/values_statement.yml new file mode 100644 index 000000000..8fb6e5550 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/values_statement.yml @@ -0,0 +1,68 @@ +file: +- statement: + - values_clause: + - keyword: VALUES + - keyword: ROW + - bracketed: + - start_bracket: ( + - quoted_literal: '''a''' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - keyword: ROW + - bracketed: + - start_bracket: ( + - quoted_literal: '''b''' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - values_clause: + - keyword: VALUES + - keyword: ROW + - bracketed: + - start_bracket: ( + - quoted_literal: '''a''' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - keyword: ROW + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: upper + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''b''' + - end_bracket: ) + - comma: ',' + - expression: + - numeric_literal: '2' + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - values_clause: + - keyword: VALUES + - keyword: ROW + - bracketed: + - start_bracket: ( + - expression: + - bare_function: CURRENT_DATE + - comma: ',' + - quoted_literal: '''2020-06-04''' + - unparsable: + - plus: + + - word: interval + - minus: '-' + - numeric_literal: '5' + - word: day + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/variable_assignment.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/variable_assignment.sql new file mode 100644 index 000000000..99636770a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/variable_assignment.sql @@ -0,0 +1,7 @@ +SELECT @var1:=COUNT(*) FROM t1; + +SET @var1:=0; + +SET @var1:=@var2:=0; + +UPDATE t1 SET c1 = 2 WHERE c1 = @var1:= 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/variable_assignment.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/variable_assignment.yml new file mode 100644 index 000000000..2af97a140 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/variable_assignment.yml @@ -0,0 +1,6 @@ +file: +- statement: + - select_statement: + - select_clause: + - unparsable: + - keyword: SELECT diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/while_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/while_label.sql new file mode 100644 index 000000000..2fc801127 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/while_label.sql @@ -0,0 +1 @@ +iteration:while _cnt <= _max_cnt do set _cnt = _cnt + 1; end while iteration; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/while_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/while_label.yml new file mode 100644 index 000000000..505883ebf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/while_label.yml @@ -0,0 +1,31 @@ +file: +- statement: + - naked_identifier: iteration + - colon: ':' + - keyword: while + - expression: + - column_reference: + - naked_identifier: _cnt + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - column_reference: + - naked_identifier: _max_cnt + - keyword: do + - statement: + - set_statement: + - keyword: set + - variable: _cnt + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: _cnt + - binary_operator: + + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - keyword: end + - keyword: while + - naked_identifier: iteration +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/while_no_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/while_no_label.sql new file mode 100644 index 000000000..a59989683 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/while_no_label.sql @@ -0,0 +1 @@ +while _cnt <= _max_cnt do set _cnt = _cnt + 1; end while; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/while_no_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/while_no_label.yml new file mode 100644 index 000000000..7f79609e1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/while_no_label.yml @@ -0,0 +1,28 @@ +file: +- statement: + - keyword: while + - expression: + - column_reference: + - naked_identifier: _cnt + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - column_reference: + - naked_identifier: _max_cnt + - keyword: do + - statement: + - set_statement: + - keyword: set + - variable: _cnt + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: _cnt + - binary_operator: + + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - keyword: end + - keyword: while +- statement_terminator: ;