Skip to content

Commit 4a53313

Browse files
committed
SGA-11783 Added support for SHOW CHARSET
1 parent 4921846 commit 4a53313

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

src/ast/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3704,6 +3704,20 @@ pub enum Statement {
37043704
history: bool,
37053705
show_options: ShowStatementOptions,
37063706
},
3707+
// ```sql
3708+
// SHOW {CHARACTER SET | CHARSET} [like_or_where]
3709+
// ```
3710+
// where:
3711+
// like_or_where: {
3712+
// LIKE 'pattern'
3713+
// | WHERE expr
3714+
// }
3715+
// MySQL specific statement
3716+
// <https://dev.mysql.com/doc/refman/8.4/en/show.html#:~:text=SHOW%20%7BCHARACTER%20SET%20%7C%20CHARSET%7D%20%5Blike_or_where%5D>
3717+
ShowCharset {
3718+
is_shorthand: bool,
3719+
filter: Option<ShowStatementFilter>,
3720+
},
37073721
/// ```sql
37083722
/// SHOW OBJECTS LIKE 'line%' IN mydb.public
37093723
/// ```
@@ -5674,6 +5688,21 @@ impl fmt::Display for Statement {
56745688
}
56755689
Ok(())
56765690
}
5691+
Statement::ShowCharset {
5692+
is_shorthand,
5693+
filter,
5694+
} => {
5695+
write!(f, "SHOW")?;
5696+
if *is_shorthand {
5697+
write!(f, " CHARSET")?;
5698+
} else {
5699+
write!(f, " CHARACTER SET")?;
5700+
}
5701+
if filter.is_some() {
5702+
write!(f, " {}", filter.as_ref().unwrap())?;
5703+
}
5704+
Ok(())
5705+
}
56775706
Statement::StartTransaction {
56785707
modes,
56795708
begin: syntax_begin,

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ impl Spanned for Statement {
477477
Statement::ShowColumns { .. } => Span::empty(),
478478
Statement::ShowTables { .. } => Span::empty(),
479479
Statement::ShowCollation { .. } => Span::empty(),
480+
Statement::ShowCharset { .. } => Span::empty(),
480481
Statement::Use(u) => u.span(),
481482
Statement::StartTransaction { .. } => Span::empty(),
482483
Statement::Comment { .. } => Span::empty(),

src/parser/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12505,13 +12505,25 @@ impl<'a> Parser<'a> {
1250512505
self.parse_show_databases(terse)
1250612506
} else if self.parse_keyword(Keyword::SCHEMAS) {
1250712507
self.parse_show_schemas(terse)
12508+
} else if self.parse_keywords(&[Keyword::CHARACTER, Keyword::SET]) {
12509+
self.parse_show_charset(false)
12510+
} else if self.parse_keyword(Keyword::CHARSET) {
12511+
self.parse_show_charset(true)
1250812512
} else {
1250912513
Ok(Statement::ShowVariable {
1251012514
variable: self.parse_identifiers()?,
1251112515
})
1251212516
}
1251312517
}
1251412518

12519+
fn parse_show_charset(&mut self, is_shorthand: bool) -> Result<Statement, ParserError> {
12520+
// parse one of keywords
12521+
Ok(Statement::ShowCharset {
12522+
is_shorthand,
12523+
filter: self.parse_show_statement_filter()?,
12524+
})
12525+
}
12526+
1251512527
fn parse_show_databases(&mut self, terse: bool) -> Result<Statement, ParserError> {
1251612528
let history = self.parse_keyword(Keyword::HISTORY);
1251712529
let show_options = self.parse_show_stmt_options()?;

tests/sqlparser_mysql.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4143,3 +4143,11 @@ fn parse_json_member_of() {
41434143
_ => panic!("Unexpected statement {stmt}"),
41444144
}
41454145
}
4146+
4147+
#[test]
4148+
fn parse_show_charset() {
4149+
let _ = mysql().verified_stmt("SHOW CHARACTER SET");
4150+
let _ = mysql().verified_stmt("SHOW CHARACTER SET LIKE 'utf8mb4%'");
4151+
let _ = mysql().verified_stmt("SHOW CHARSET WHERE charset = 'utf8mb4%'");
4152+
let _ = mysql().verified_stmt("SHOW CHARSET LIKE 'utf8mb4%'");
4153+
}

0 commit comments

Comments
 (0)