Skip to content

Commit 61089f9

Browse files
invmMichael Ionov
and
Michael Ionov
authored
feat: add mysql show status statement (#1119)
Co-authored-by: Michael Ionov <[email protected]>
1 parent bcecd85 commit 61089f9

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

src/ast/mod.rs

+28
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,16 @@ pub enum Statement {
19551955
/// Note: this is a PostgreSQL-specific statement.
19561956
ShowVariable { variable: Vec<Ident> },
19571957
/// ```sql
1958+
/// SHOW [GLOBAL | SESSION] STATUS [LIKE 'pattern' | WHERE expr]
1959+
/// ```
1960+
///
1961+
/// Note: this is a MySQL-specific statement.
1962+
ShowStatus {
1963+
filter: Option<ShowStatementFilter>,
1964+
global: bool,
1965+
session: bool,
1966+
},
1967+
/// ```sql
19581968
/// SHOW VARIABLES
19591969
/// ```
19601970
///
@@ -3387,6 +3397,24 @@ impl fmt::Display for Statement {
33873397
}
33883398
Ok(())
33893399
}
3400+
Statement::ShowStatus {
3401+
filter,
3402+
global,
3403+
session,
3404+
} => {
3405+
write!(f, "SHOW")?;
3406+
if *global {
3407+
write!(f, " GLOBAL")?;
3408+
}
3409+
if *session {
3410+
write!(f, " SESSION")?;
3411+
}
3412+
write!(f, " STATUS")?;
3413+
if filter.is_some() {
3414+
write!(f, " {}", filter.as_ref().unwrap())?;
3415+
}
3416+
Ok(())
3417+
}
33903418
Statement::ShowVariables {
33913419
filter,
33923420
global,

src/parser/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -7097,6 +7097,14 @@ impl<'a> Parser<'a> {
70977097
session,
70987098
global,
70997099
})
7100+
} else if self.parse_keyword(Keyword::STATUS)
7101+
&& dialect_of!(self is MySqlDialect | GenericDialect)
7102+
{
7103+
Ok(Statement::ShowStatus {
7104+
filter: self.parse_show_statement_filter()?,
7105+
session,
7106+
global,
7107+
})
71007108
} else {
71017109
Ok(Statement::ShowVariable {
71027110
variable: self.parse_identifiers()?,

tests/sqlparser_mysql.rs

+30
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,36 @@ fn parse_show_columns() {
288288
);
289289
}
290290

291+
#[test]
292+
fn parse_show_status() {
293+
assert_eq!(
294+
mysql_and_generic().verified_stmt("SHOW SESSION STATUS LIKE 'ssl_cipher'"),
295+
Statement::ShowStatus {
296+
filter: Some(ShowStatementFilter::Like("ssl_cipher".into())),
297+
session: true,
298+
global: false
299+
}
300+
);
301+
assert_eq!(
302+
mysql_and_generic().verified_stmt("SHOW GLOBAL STATUS LIKE 'ssl_cipher'"),
303+
Statement::ShowStatus {
304+
filter: Some(ShowStatementFilter::Like("ssl_cipher".into())),
305+
session: false,
306+
global: true
307+
}
308+
);
309+
assert_eq!(
310+
mysql_and_generic().verified_stmt("SHOW STATUS WHERE value = 2"),
311+
Statement::ShowStatus {
312+
filter: Some(ShowStatementFilter::Where(
313+
mysql_and_generic().verified_expr("value = 2")
314+
)),
315+
session: false,
316+
global: false
317+
}
318+
);
319+
}
320+
291321
#[test]
292322
fn parse_show_tables() {
293323
assert_eq!(

0 commit comments

Comments
 (0)