Add support for SHOW CHARSET (#1974)
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run

Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
etgarperets 2025-07-29 13:38:07 +03:00 committed by GitHub
parent bde269b56f
commit 15d8bfea62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 61 additions and 0 deletions

View file

@ -3696,6 +3696,12 @@ pub enum Statement {
history: bool,
show_options: ShowStatementOptions,
},
// ```sql
// SHOW {CHARACTER SET | CHARSET}
// ```
// [MySQL]:
// <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>
ShowCharset(ShowCharset),
/// ```sql
/// SHOW OBJECTS LIKE 'line%' IN mydb.public
/// ```
@ -5680,6 +5686,7 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::ShowCharset(show_stm) => show_stm.fmt(f),
Statement::StartTransaction {
modes,
begin: syntax_begin,
@ -9859,6 +9866,32 @@ impl fmt::Display for ShowStatementIn {
}
}
/// A Show Charset statement
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct ShowCharset {
/// The statement can be written as `SHOW CHARSET` or `SHOW CHARACTER SET`
/// true means CHARSET was used and false means CHARACTER SET was used
pub is_shorthand: bool,
pub filter: Option<ShowStatementFilter>,
}
impl fmt::Display for ShowCharset {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "SHOW")?;
if self.is_shorthand {
write!(f, " CHARSET")?;
} else {
write!(f, " CHARACTER SET")?;
}
if self.filter.is_some() {
write!(f, " {}", self.filter.as_ref().unwrap())?;
}
Ok(())
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]

View file

@ -477,6 +477,7 @@ impl Spanned for Statement {
Statement::ShowColumns { .. } => Span::empty(),
Statement::ShowTables { .. } => Span::empty(),
Statement::ShowCollation { .. } => Span::empty(),
Statement::ShowCharset { .. } => Span::empty(),
Statement::Use(u) => u.span(),
Statement::StartTransaction { .. } => Span::empty(),
Statement::Comment { .. } => Span::empty(),

View file

@ -12595,6 +12595,10 @@ impl<'a> Parser<'a> {
self.parse_show_databases(terse)
} else if self.parse_keyword(Keyword::SCHEMAS) {
self.parse_show_schemas(terse)
} else if self.parse_keywords(&[Keyword::CHARACTER, Keyword::SET]) {
self.parse_show_charset(false)
} else if self.parse_keyword(Keyword::CHARSET) {
self.parse_show_charset(true)
} else {
Ok(Statement::ShowVariable {
variable: self.parse_identifiers()?,
@ -12602,6 +12606,14 @@ impl<'a> Parser<'a> {
}
}
fn parse_show_charset(&mut self, is_shorthand: bool) -> Result<Statement, ParserError> {
// parse one of keywords
Ok(Statement::ShowCharset(ShowCharset {
is_shorthand,
filter: self.parse_show_statement_filter()?,
}))
}
fn parse_show_databases(&mut self, terse: bool) -> Result<Statement, ParserError> {
let history = self.parse_keyword(Keyword::HISTORY);
let show_options = self.parse_show_stmt_options()?;

View file

@ -4143,3 +4143,18 @@ fn parse_json_member_of() {
_ => panic!("Unexpected statement {stmt}"),
}
}
#[test]
fn parse_show_charset() {
let res = mysql().verified_stmt("SHOW CHARACTER SET");
assert_eq!(
res,
Statement::ShowCharset(ShowCharset {
is_shorthand: false,
filter: None
})
);
mysql().verified_stmt("SHOW CHARACTER SET LIKE 'utf8mb4%'");
mysql().verified_stmt("SHOW CHARSET WHERE charset = 'utf8mb4%'");
mysql().verified_stmt("SHOW CHARSET LIKE 'utf8mb4%'");
}