feat: add mysql show status statement (#1119)

Co-authored-by: Michael Ionov <michael@appdome.com>
This commit is contained in:
Michael Ionov 2024-02-04 15:52:46 +02:00 committed by GitHub
parent bcecd853f7
commit 61089f977c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 66 additions and 0 deletions

View file

@ -1955,6 +1955,16 @@ pub enum Statement {
/// Note: this is a PostgreSQL-specific statement.
ShowVariable { variable: Vec<Ident> },
/// ```sql
/// SHOW [GLOBAL | SESSION] STATUS [LIKE 'pattern' | WHERE expr]
/// ```
///
/// Note: this is a MySQL-specific statement.
ShowStatus {
filter: Option<ShowStatementFilter>,
global: bool,
session: bool,
},
/// ```sql
/// SHOW VARIABLES
/// ```
///
@ -3387,6 +3397,24 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::ShowStatus {
filter,
global,
session,
} => {
write!(f, "SHOW")?;
if *global {
write!(f, " GLOBAL")?;
}
if *session {
write!(f, " SESSION")?;
}
write!(f, " STATUS")?;
if filter.is_some() {
write!(f, " {}", filter.as_ref().unwrap())?;
}
Ok(())
}
Statement::ShowVariables {
filter,
global,

View file

@ -7097,6 +7097,14 @@ impl<'a> Parser<'a> {
session,
global,
})
} else if self.parse_keyword(Keyword::STATUS)
&& dialect_of!(self is MySqlDialect | GenericDialect)
{
Ok(Statement::ShowStatus {
filter: self.parse_show_statement_filter()?,
session,
global,
})
} else {
Ok(Statement::ShowVariable {
variable: self.parse_identifiers()?,

View file

@ -288,6 +288,36 @@ fn parse_show_columns() {
);
}
#[test]
fn parse_show_status() {
assert_eq!(
mysql_and_generic().verified_stmt("SHOW SESSION STATUS LIKE 'ssl_cipher'"),
Statement::ShowStatus {
filter: Some(ShowStatementFilter::Like("ssl_cipher".into())),
session: true,
global: false
}
);
assert_eq!(
mysql_and_generic().verified_stmt("SHOW GLOBAL STATUS LIKE 'ssl_cipher'"),
Statement::ShowStatus {
filter: Some(ShowStatementFilter::Like("ssl_cipher".into())),
session: false,
global: true
}
);
assert_eq!(
mysql_and_generic().verified_stmt("SHOW STATUS WHERE value = 2"),
Statement::ShowStatus {
filter: Some(ShowStatementFilter::Where(
mysql_and_generic().verified_expr("value = 2")
)),
session: false,
global: false
}
);
}
#[test]
fn parse_show_tables() {
assert_eq!(