Skip to content

Commit e2b9437

Browse files
ovrvasilev-alex
andauthored
feat: Initial support for parsing MySQL show variables (apache#559)
Co-authored-by: Alex Vasilev <[email protected]>
1 parent 231370a commit e2b9437

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/ast/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,10 @@ pub enum Statement {
996996
///
997997
/// Note: this is a PostgreSQL-specific statement.
998998
ShowVariable { variable: Vec<Ident> },
999+
/// SHOW VARIABLES
1000+
///
1001+
/// Note: this is a MySQL-specific statement.
1002+
ShowVariables { filter: Option<ShowStatementFilter> },
9991003
/// SHOW CREATE TABLE
10001004
///
10011005
/// Note: this is a MySQL-specific statement.
@@ -1787,6 +1791,13 @@ impl fmt::Display for Statement {
17871791
}
17881792
Ok(())
17891793
}
1794+
Statement::ShowVariables { filter } => {
1795+
write!(f, "SHOW VARIABLES")?;
1796+
if filter.is_some() {
1797+
write!(f, " {}", filter.as_ref().unwrap())?;
1798+
}
1799+
Ok(())
1800+
}
17901801
Statement::ShowCreate { obj_type, obj_name } => {
17911802
write!(
17921803
f,

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ define_keywords!(
543543
VALUE_OF,
544544
VARBINARY,
545545
VARCHAR,
546+
VARIABLES,
546547
VARYING,
547548
VAR_POP,
548549
VAR_SAMP,

src/parser.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,6 +3694,13 @@ impl<'a> Parser<'a> {
36943694
Ok(self.parse_show_columns()?)
36953695
} else if self.parse_one_of_keywords(&[Keyword::CREATE]).is_some() {
36963696
Ok(self.parse_show_create()?)
3697+
} else if self.parse_keyword(Keyword::VARIABLES)
3698+
&& dialect_of!(self is MySqlDialect | GenericDialect)
3699+
{
3700+
// TODO: Support GLOBAL|SESSION
3701+
Ok(Statement::ShowVariables {
3702+
filter: self.parse_show_statement_filter()?,
3703+
})
36973704
} else {
36983705
Ok(Statement::ShowVariable {
36993706
variable: self.parse_identifiers()?,

tests/sqlparser_mysql.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,13 @@ fn parse_substring_in_select() {
820820
}
821821
}
822822

823+
#[test]
824+
fn parse_show_variables() {
825+
mysql_and_generic().verified_stmt("SHOW VARIABLES");
826+
mysql_and_generic().verified_stmt("SHOW VARIABLES LIKE 'admin%'");
827+
mysql_and_generic().verified_stmt("SHOW VARIABLES WHERE value = '3306'");
828+
}
829+
823830
#[test]
824831
fn parse_kill() {
825832
let stmt = mysql_and_generic().verified_stmt("KILL CONNECTION 5");

0 commit comments

Comments
 (0)