mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 23:14:07 +00:00
feat: add mysql show status statement (#1119)
Co-authored-by: Michael Ionov <michael@appdome.com>
This commit is contained in:
parent
bcecd853f7
commit
61089f977c
3 changed files with 66 additions and 0 deletions
|
@ -1955,6 +1955,16 @@ pub enum Statement {
|
||||||
/// Note: this is a PostgreSQL-specific statement.
|
/// Note: this is a PostgreSQL-specific statement.
|
||||||
ShowVariable { variable: Vec<Ident> },
|
ShowVariable { variable: Vec<Ident> },
|
||||||
/// ```sql
|
/// ```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
|
/// SHOW VARIABLES
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
@ -3387,6 +3397,24 @@ impl fmt::Display for Statement {
|
||||||
}
|
}
|
||||||
Ok(())
|
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 {
|
Statement::ShowVariables {
|
||||||
filter,
|
filter,
|
||||||
global,
|
global,
|
||||||
|
|
|
@ -7097,6 +7097,14 @@ impl<'a> Parser<'a> {
|
||||||
session,
|
session,
|
||||||
global,
|
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 {
|
} else {
|
||||||
Ok(Statement::ShowVariable {
|
Ok(Statement::ShowVariable {
|
||||||
variable: self.parse_identifiers()?,
|
variable: self.parse_identifiers()?,
|
||||||
|
|
|
@ -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]
|
#[test]
|
||||||
fn parse_show_tables() {
|
fn parse_show_tables() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue