mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-24 07:54:06 +00:00
feat: Initial support for parsing MySQL show variables (#559)
Co-authored-by: Alex Vasilev <vaspiring@gmail.com>
This commit is contained in:
parent
231370a770
commit
e2b943799a
4 changed files with 26 additions and 0 deletions
|
@ -996,6 +996,10 @@ pub enum Statement {
|
||||||
///
|
///
|
||||||
/// Note: this is a PostgreSQL-specific statement.
|
/// Note: this is a PostgreSQL-specific statement.
|
||||||
ShowVariable { variable: Vec<Ident> },
|
ShowVariable { variable: Vec<Ident> },
|
||||||
|
/// SHOW VARIABLES
|
||||||
|
///
|
||||||
|
/// Note: this is a MySQL-specific statement.
|
||||||
|
ShowVariables { filter: Option<ShowStatementFilter> },
|
||||||
/// SHOW CREATE TABLE
|
/// SHOW CREATE TABLE
|
||||||
///
|
///
|
||||||
/// Note: this is a MySQL-specific statement.
|
/// Note: this is a MySQL-specific statement.
|
||||||
|
@ -1787,6 +1791,13 @@ impl fmt::Display for Statement {
|
||||||
}
|
}
|
||||||
Ok(())
|
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 } => {
|
Statement::ShowCreate { obj_type, obj_name } => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -543,6 +543,7 @@ define_keywords!(
|
||||||
VALUE_OF,
|
VALUE_OF,
|
||||||
VARBINARY,
|
VARBINARY,
|
||||||
VARCHAR,
|
VARCHAR,
|
||||||
|
VARIABLES,
|
||||||
VARYING,
|
VARYING,
|
||||||
VAR_POP,
|
VAR_POP,
|
||||||
VAR_SAMP,
|
VAR_SAMP,
|
||||||
|
|
|
@ -3694,6 +3694,13 @@ impl<'a> Parser<'a> {
|
||||||
Ok(self.parse_show_columns()?)
|
Ok(self.parse_show_columns()?)
|
||||||
} else if self.parse_one_of_keywords(&[Keyword::CREATE]).is_some() {
|
} else if self.parse_one_of_keywords(&[Keyword::CREATE]).is_some() {
|
||||||
Ok(self.parse_show_create()?)
|
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 {
|
} else {
|
||||||
Ok(Statement::ShowVariable {
|
Ok(Statement::ShowVariable {
|
||||||
variable: self.parse_identifiers()?,
|
variable: self.parse_identifiers()?,
|
||||||
|
|
|
@ -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]
|
#[test]
|
||||||
fn parse_kill() {
|
fn parse_kill() {
|
||||||
let stmt = mysql_and_generic().verified_stmt("KILL CONNECTION 5");
|
let stmt = mysql_and_generic().verified_stmt("KILL CONNECTION 5");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue