From 749b061fbfcdd997f0097152ec4bf9b7376b8c4e Mon Sep 17 00:00:00 2001 From: Hans Ott Date: Fri, 11 Oct 2024 17:15:18 +0200 Subject: [PATCH] MySQL dialect: Add support for hash comments (#1466) --- src/tokenizer.rs | 5 +++-- tests/sqlparser_common.rs | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 6d0c86ff2..4186ec824 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -43,7 +43,8 @@ use sqlparser_derive::{Visit, VisitMut}; use crate::ast::DollarQuotedString; use crate::dialect::Dialect; use crate::dialect::{ - BigQueryDialect, DuckDbDialect, GenericDialect, PostgreSqlDialect, SnowflakeDialect, + BigQueryDialect, DuckDbDialect, GenericDialect, MySqlDialect, PostgreSqlDialect, + SnowflakeDialect, }; use crate::keywords::{Keyword, ALL_KEYWORDS, ALL_KEYWORDS_INDEX}; @@ -1140,7 +1141,7 @@ impl<'a> Tokenizer<'a> { } '{' => self.consume_and_return(chars, Token::LBrace), '}' => self.consume_and_return(chars, Token::RBrace), - '#' if dialect_of!(self is SnowflakeDialect | BigQueryDialect) => { + '#' if dialect_of!(self is SnowflakeDialect | BigQueryDialect | MySqlDialect) => { chars.next(); // consume the '#', starting a snowflake single-line comment let comment = self.tokenize_single_line_comment(chars); Ok(Some(Token::Whitespace(Whitespace::SingleLineComment { diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 5327880a4..7140109b2 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -9923,7 +9923,11 @@ fn test_release_savepoint() { #[test] fn test_comment_hash_syntax() { let dialects = TestedDialects { - dialects: vec![Box::new(BigQueryDialect {}), Box::new(SnowflakeDialect {})], + dialects: vec![ + Box::new(BigQueryDialect {}), + Box::new(SnowflakeDialect {}), + Box::new(MySqlDialect {}), + ], options: None, }; let sql = r#"