Skip to content

Commit

Permalink
Support global and session parts in show variables for mysql and gene…
Browse files Browse the repository at this point in the history
…ric dialects (#1032)
  • Loading branch information
emin100 authored Nov 20, 2023
1 parent dc2ceed commit c0c2d58
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,11 @@ pub enum Statement {
/// SHOW VARIABLES
///
/// Note: this is a MySQL-specific statement.
ShowVariables { filter: Option<ShowStatementFilter> },
ShowVariables {
filter: Option<ShowStatementFilter>,
global: bool,
session: bool,
},
/// SHOW CREATE TABLE
///
/// Note: this is a MySQL-specific statement.
Expand Down Expand Up @@ -2977,8 +2981,19 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::ShowVariables { filter } => {
write!(f, "SHOW VARIABLES")?;
Statement::ShowVariables {
filter,
global,
session,
} => {
write!(f, "SHOW")?;
if *global {
write!(f, " GLOBAL")?;
}
if *session {
write!(f, " SESSION")?;
}
write!(f, " VARIABLES")?;
if filter.is_some() {
write!(f, " {}", filter.as_ref().unwrap())?;
}
Expand Down
5 changes: 4 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6443,6 +6443,8 @@ impl<'a> Parser<'a> {
pub fn parse_show(&mut self) -> Result<Statement, ParserError> {
let extended = self.parse_keyword(Keyword::EXTENDED);
let full = self.parse_keyword(Keyword::FULL);
let session = self.parse_keyword(Keyword::SESSION);
let global = self.parse_keyword(Keyword::GLOBAL);
if self
.parse_one_of_keywords(&[Keyword::COLUMNS, Keyword::FIELDS])
.is_some()
Expand All @@ -6463,9 +6465,10 @@ impl<'a> Parser<'a> {
} else if self.parse_keyword(Keyword::VARIABLES)
&& dialect_of!(self is MySqlDialect | GenericDialect)
{
// TODO: Support GLOBAL|SESSION
Ok(Statement::ShowVariables {
filter: self.parse_show_statement_filter()?,
session,
global,
})
} else {
Ok(Statement::ShowVariable {
Expand Down
6 changes: 6 additions & 0 deletions tests/sqlparser_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,12 @@ fn parse_show_variables() {
mysql_and_generic().verified_stmt("SHOW VARIABLES");
mysql_and_generic().verified_stmt("SHOW VARIABLES LIKE 'admin%'");
mysql_and_generic().verified_stmt("SHOW VARIABLES WHERE value = '3306'");
mysql_and_generic().verified_stmt("SHOW GLOBAL VARIABLES");
mysql_and_generic().verified_stmt("SHOW GLOBAL VARIABLES LIKE 'admin%'");
mysql_and_generic().verified_stmt("SHOW GLOBAL VARIABLES WHERE value = '3306'");
mysql_and_generic().verified_stmt("SHOW SESSION VARIABLES");
mysql_and_generic().verified_stmt("SHOW SESSION VARIABLES LIKE 'admin%'");
mysql_and_generic().verified_stmt("SHOW GLOBAL VARIABLES WHERE value = '3306'");
}

#[test]
Expand Down

0 comments on commit c0c2d58

Please sign in to comment.