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

This commit is contained in:
Mehmet Emin KARAKAŞ 2023-11-20 22:47:55 +03:00 committed by GitHub
parent dc2ceedeea
commit c0c2d58910
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 4 deletions

View file

@ -1739,7 +1739,11 @@ pub enum Statement {
/// SHOW VARIABLES /// SHOW VARIABLES
/// ///
/// Note: this is a MySQL-specific statement. /// Note: this is a MySQL-specific statement.
ShowVariables { filter: Option<ShowStatementFilter> }, ShowVariables {
filter: Option<ShowStatementFilter>,
global: bool,
session: bool,
},
/// SHOW CREATE TABLE /// SHOW CREATE TABLE
/// ///
/// Note: this is a MySQL-specific statement. /// Note: this is a MySQL-specific statement.
@ -2977,8 +2981,19 @@ impl fmt::Display for Statement {
} }
Ok(()) Ok(())
} }
Statement::ShowVariables { filter } => { Statement::ShowVariables {
write!(f, "SHOW VARIABLES")?; filter,
global,
session,
} => {
write!(f, "SHOW")?;
if *global {
write!(f, " GLOBAL")?;
}
if *session {
write!(f, " SESSION")?;
}
write!(f, " VARIABLES")?;
if filter.is_some() { if filter.is_some() {
write!(f, " {}", filter.as_ref().unwrap())?; write!(f, " {}", filter.as_ref().unwrap())?;
} }

View file

@ -6443,6 +6443,8 @@ impl<'a> Parser<'a> {
pub fn parse_show(&mut self) -> Result<Statement, ParserError> { pub fn parse_show(&mut self) -> Result<Statement, ParserError> {
let extended = self.parse_keyword(Keyword::EXTENDED); let extended = self.parse_keyword(Keyword::EXTENDED);
let full = self.parse_keyword(Keyword::FULL); let full = self.parse_keyword(Keyword::FULL);
let session = self.parse_keyword(Keyword::SESSION);
let global = self.parse_keyword(Keyword::GLOBAL);
if self if self
.parse_one_of_keywords(&[Keyword::COLUMNS, Keyword::FIELDS]) .parse_one_of_keywords(&[Keyword::COLUMNS, Keyword::FIELDS])
.is_some() .is_some()
@ -6463,9 +6465,10 @@ impl<'a> Parser<'a> {
} else if self.parse_keyword(Keyword::VARIABLES) } else if self.parse_keyword(Keyword::VARIABLES)
&& dialect_of!(self is MySqlDialect | GenericDialect) && dialect_of!(self is MySqlDialect | GenericDialect)
{ {
// TODO: Support GLOBAL|SESSION
Ok(Statement::ShowVariables { Ok(Statement::ShowVariables {
filter: self.parse_show_statement_filter()?, filter: self.parse_show_statement_filter()?,
session,
global,
}) })
} else { } else {
Ok(Statement::ShowVariable { Ok(Statement::ShowVariable {

View file

@ -1512,6 +1512,12 @@ fn parse_show_variables() {
mysql_and_generic().verified_stmt("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 LIKE 'admin%'");
mysql_and_generic().verified_stmt("SHOW VARIABLES WHERE value = '3306'"); 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] #[test]