Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support global and session parts in show variables for mysql and generic dialects #1032

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 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,17 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::ShowVariables { filter } => {
write!(f, "SHOW VARIABLES")?;
Statement::ShowVariables {
filter,
global,
session,
} => {
write!(
f,
"SHOW {global}{session}VARIABLES",
global = if *global { "GLOBAL " } else { "" },
session = if *session { "SESSION " } else { "" }
)?;
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 @@ -6330,6 +6330,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 @@ -6350,9 +6352,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 @@ -1503,6 +1503,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