Skip to content

Commit

Permalink
MySQL dialect: Add support for hash comments (#1466)
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott authored Oct 11, 2024
1 parent a4fa9e0 commit 749b061
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand Down

0 comments on commit 749b061

Please sign in to comment.