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

feat: Support parsing MySQL show variables #559

Merged
merged 1 commit into from Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/ast/mod.rs
Expand Up @@ -996,6 +996,10 @@ pub enum Statement {
///
/// Note: this is a PostgreSQL-specific statement.
ShowVariable { variable: Vec<Ident> },
/// SHOW VARIABLES
///
/// Note: this is a MySQL-specific statement.
ShowVariables { filter: Option<ShowStatementFilter> },
/// SHOW CREATE TABLE
///
/// Note: this is a MySQL-specific statement.
Expand Down Expand Up @@ -1787,6 +1791,13 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::ShowVariables { filter } => {
write!(f, "SHOW VARIABLES")?;
if filter.is_some() {
write!(f, " {}", filter.as_ref().unwrap())?;
}
Ok(())
}
Statement::ShowCreate { obj_type, obj_name } => {
write!(
f,
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Expand Up @@ -543,6 +543,7 @@ define_keywords!(
VALUE_OF,
VARBINARY,
VARCHAR,
VARIABLES,
VARYING,
VAR_POP,
VAR_SAMP,
Expand Down
7 changes: 7 additions & 0 deletions src/parser.rs
Expand Up @@ -3694,6 +3694,13 @@ impl<'a> Parser<'a> {
Ok(self.parse_show_columns()?)
} else if self.parse_one_of_keywords(&[Keyword::CREATE]).is_some() {
Ok(self.parse_show_create()?)
} 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()?,
})
} else {
Ok(Statement::ShowVariable {
variable: self.parse_identifiers()?,
Expand Down
7 changes: 7 additions & 0 deletions tests/sqlparser_mysql.rs
Expand Up @@ -820,6 +820,13 @@ fn parse_substring_in_select() {
}
}

#[test]
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'");
}

#[test]
fn parse_kill() {
let stmt = mysql_and_generic().verified_stmt("KILL CONNECTION 5");
Expand Down