Skip to content

Commit c0c2d58

Browse files
authored
Support global and session parts in show variables for mysql and generic dialects (#1032)
1 parent dc2ceed commit c0c2d58

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/ast/mod.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,11 @@ pub enum Statement {
17391739
/// SHOW VARIABLES
17401740
///
17411741
/// Note: this is a MySQL-specific statement.
1742-
ShowVariables { filter: Option<ShowStatementFilter> },
1742+
ShowVariables {
1743+
filter: Option<ShowStatementFilter>,
1744+
global: bool,
1745+
session: bool,
1746+
},
17431747
/// SHOW CREATE TABLE
17441748
///
17451749
/// Note: this is a MySQL-specific statement.
@@ -2977,8 +2981,19 @@ impl fmt::Display for Statement {
29772981
}
29782982
Ok(())
29792983
}
2980-
Statement::ShowVariables { filter } => {
2981-
write!(f, "SHOW VARIABLES")?;
2984+
Statement::ShowVariables {
2985+
filter,
2986+
global,
2987+
session,
2988+
} => {
2989+
write!(f, "SHOW")?;
2990+
if *global {
2991+
write!(f, " GLOBAL")?;
2992+
}
2993+
if *session {
2994+
write!(f, " SESSION")?;
2995+
}
2996+
write!(f, " VARIABLES")?;
29822997
if filter.is_some() {
29832998
write!(f, " {}", filter.as_ref().unwrap())?;
29842999
}

src/parser/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6443,6 +6443,8 @@ impl<'a> Parser<'a> {
64436443
pub fn parse_show(&mut self) -> Result<Statement, ParserError> {
64446444
let extended = self.parse_keyword(Keyword::EXTENDED);
64456445
let full = self.parse_keyword(Keyword::FULL);
6446+
let session = self.parse_keyword(Keyword::SESSION);
6447+
let global = self.parse_keyword(Keyword::GLOBAL);
64466448
if self
64476449
.parse_one_of_keywords(&[Keyword::COLUMNS, Keyword::FIELDS])
64486450
.is_some()
@@ -6463,9 +6465,10 @@ impl<'a> Parser<'a> {
64636465
} else if self.parse_keyword(Keyword::VARIABLES)
64646466
&& dialect_of!(self is MySqlDialect | GenericDialect)
64656467
{
6466-
// TODO: Support GLOBAL|SESSION
64676468
Ok(Statement::ShowVariables {
64686469
filter: self.parse_show_statement_filter()?,
6470+
session,
6471+
global,
64696472
})
64706473
} else {
64716474
Ok(Statement::ShowVariable {

tests/sqlparser_mysql.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,12 @@ fn parse_show_variables() {
15121512
mysql_and_generic().verified_stmt("SHOW VARIABLES");
15131513
mysql_and_generic().verified_stmt("SHOW VARIABLES LIKE 'admin%'");
15141514
mysql_and_generic().verified_stmt("SHOW VARIABLES WHERE value = '3306'");
1515+
mysql_and_generic().verified_stmt("SHOW GLOBAL VARIABLES");
1516+
mysql_and_generic().verified_stmt("SHOW GLOBAL VARIABLES LIKE 'admin%'");
1517+
mysql_and_generic().verified_stmt("SHOW GLOBAL VARIABLES WHERE value = '3306'");
1518+
mysql_and_generic().verified_stmt("SHOW SESSION VARIABLES");
1519+
mysql_and_generic().verified_stmt("SHOW SESSION VARIABLES LIKE 'admin%'");
1520+
mysql_and_generic().verified_stmt("SHOW GLOBAL VARIABLES WHERE value = '3306'");
15151521
}
15161522

15171523
#[test]

0 commit comments

Comments
 (0)