Skip to content

Commit 0b8d232

Browse files
vasilev-alexMazterQyou
authored andcommitted
feat: support parsing MySQL show variables (#6)
1 parent 3d1cfa6 commit 0b8d232

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

src/ast/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,10 @@ pub enum Statement {
863863
///
864864
/// Note: this is a PostgreSQL-specific statement.
865865
ShowVariable { variable: Vec<Ident> },
866+
/// SHOW VARIABLES
867+
///
868+
/// Note: this is a MySQL-specific statement.
869+
ShowVariables { filter: Option<ShowStatementFilter> },
866870
/// SHOW CREATE TABLE
867871
///
868872
/// Note: this is a MySQL-specific statement.
@@ -1500,6 +1504,13 @@ impl fmt::Display for Statement {
15001504
}
15011505
Ok(())
15021506
}
1507+
Statement::ShowVariables { filter } => {
1508+
write!(f, "SHOW VARIABLES")?;
1509+
if filter.is_some() {
1510+
write!(f, " {}", filter.as_ref().unwrap().to_string())?;
1511+
}
1512+
Ok(())
1513+
}
15031514
Statement::ShowCreate { obj_type, obj_name } => {
15041515
write!(
15051516
f,

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ define_keywords!(
522522
VALUE_OF,
523523
VARBINARY,
524524
VARCHAR,
525+
VARIABLES,
525526
VARYING,
526527
VAR_POP,
527528
VAR_SAMP,

src/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,6 +3204,10 @@ impl<'a> Parser<'a> {
32043204
Ok(self.parse_show_columns()?)
32053205
} else if self.parse_one_of_keywords(&[Keyword::CREATE]).is_some() {
32063206
Ok(self.parse_show_create()?)
3207+
} else if self.parse_one_of_keywords(&[Keyword::VARIABLES]).is_some() {
3208+
Ok(Statement::ShowVariables {
3209+
filter: self.parse_show_statement_filter()?,
3210+
})
32073211
} else {
32083212
Ok(Statement::ShowVariable {
32093213
variable: self.parse_identifiers()?,

tests/sqlparser_mysql.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,13 @@ fn parse_substring_in_select() {
768768
}
769769
}
770770

771+
#[test]
772+
fn parse_show_variables() {
773+
mysql().verified_stmt("SHOW VARIABLES");
774+
mysql().verified_stmt("SHOW VARIABLES LIKE 'admin%'");
775+
mysql().verified_stmt("SHOW VARIABLES WHERE value = '3306'");
776+
}
777+
771778
#[test]
772779
fn parse_set_names() {
773780
let stmt = mysql_and_generic().verified_stmt("SET NAMES utf8mb4");

0 commit comments

Comments
 (0)