Skip to content

Commit b6d7ddc

Browse files
vasilev-alexmcheshkov
authored andcommitted
feat: support parsing MySQL show variables (#6)
Can drop this after rebase on commit e2b9437 "feat: Initial support for parsing MySQL show variables (apache#559)", first released in 0.21.0
1 parent b213951 commit b6d7ddc

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/ast/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,10 @@ pub enum Statement {
991991
///
992992
/// Note: this is a PostgreSQL-specific statement.
993993
ShowVariable { variable: Vec<Ident> },
994+
/// SHOW VARIABLES
995+
///
996+
/// Note: this is a MySQL-specific statement.
997+
ShowVariables { filter: Option<ShowStatementFilter> },
994998
/// SHOW CREATE TABLE
995999
///
9961000
/// Note: this is a MySQL-specific statement.
@@ -1739,6 +1743,13 @@ impl fmt::Display for Statement {
17391743
}
17401744
Ok(())
17411745
}
1746+
Statement::ShowVariables { filter } => {
1747+
write!(f, "SHOW VARIABLES")?;
1748+
if filter.is_some() {
1749+
write!(f, " {}", filter.as_ref().unwrap().to_string())?;
1750+
}
1751+
Ok(())
1752+
}
17421753
Statement::ShowCreate { obj_type, obj_name } => {
17431754
write!(
17441755
f,

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ define_keywords!(
536536
VALUE_OF,
537537
VARBINARY,
538538
VARCHAR,
539+
VARIABLES,
539540
VARYING,
540541
VAR_POP,
541542
VAR_SAMP,

src/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,6 +3542,10 @@ impl<'a> Parser<'a> {
35423542
Ok(self.parse_show_columns()?)
35433543
} else if self.parse_one_of_keywords(&[Keyword::CREATE]).is_some() {
35443544
Ok(self.parse_show_create()?)
3545+
} else if self.parse_one_of_keywords(&[Keyword::VARIABLES]).is_some() {
3546+
Ok(Statement::ShowVariables {
3547+
filter: self.parse_show_statement_filter()?,
3548+
})
35453549
} else {
35463550
Ok(Statement::ShowVariable {
35473551
variable: self.parse_identifiers()?,

tests/sqlparser_mysql.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,13 @@ fn parse_kill() {
800800
);
801801
}
802802

803+
#[test]
804+
fn parse_show_variables() {
805+
mysql().verified_stmt("SHOW VARIABLES");
806+
mysql().verified_stmt("SHOW VARIABLES LIKE 'admin%'");
807+
mysql().verified_stmt("SHOW VARIABLES WHERE value = '3306'");
808+
}
809+
803810
fn mysql() -> TestedDialects {
804811
TestedDialects {
805812
dialects: vec![Box::new(MySqlDialect {})],

0 commit comments

Comments
 (0)