mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-20 06:00:15 +00:00
Support SHOW COLLATION
(#564)
This commit is contained in:
parent
54a29e872d
commit
18881f8fcf
4 changed files with 47 additions and 0 deletions
|
@ -1036,6 +1036,10 @@ pub enum Statement {
|
||||||
db_name: Option<Ident>,
|
db_name: Option<Ident>,
|
||||||
filter: Option<ShowStatementFilter>,
|
filter: Option<ShowStatementFilter>,
|
||||||
},
|
},
|
||||||
|
/// SHOW COLLATION
|
||||||
|
///
|
||||||
|
/// Note: this is a MySQL-specific statement.
|
||||||
|
ShowCollation { filter: Option<ShowStatementFilter> },
|
||||||
/// USE
|
/// USE
|
||||||
///
|
///
|
||||||
/// Note: This is a MySQL-specific statement.
|
/// Note: This is a MySQL-specific statement.
|
||||||
|
@ -1892,6 +1896,13 @@ impl fmt::Display for Statement {
|
||||||
write!(f, "USE {}", db_name)?;
|
write!(f, "USE {}", db_name)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Statement::ShowCollation { filter } => {
|
||||||
|
write!(f, "SHOW COLLATION")?;
|
||||||
|
if let Some(filter) = filter {
|
||||||
|
write!(f, " {}", filter)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Statement::StartTransaction { modes } => {
|
Statement::StartTransaction { modes } => {
|
||||||
write!(f, "START TRANSACTION")?;
|
write!(f, "START TRANSACTION")?;
|
||||||
if !modes.is_empty() {
|
if !modes.is_empty() {
|
||||||
|
|
|
@ -131,6 +131,7 @@ define_keywords!(
|
||||||
CLUSTER,
|
CLUSTER,
|
||||||
COALESCE,
|
COALESCE,
|
||||||
COLLATE,
|
COLLATE,
|
||||||
|
COLLATION,
|
||||||
COLLECT,
|
COLLECT,
|
||||||
COLUMN,
|
COLUMN,
|
||||||
COLUMNS,
|
COLUMNS,
|
||||||
|
|
|
@ -3758,6 +3758,8 @@ impl<'a> Parser<'a> {
|
||||||
))
|
))
|
||||||
} 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::COLLATION) {
|
||||||
|
Ok(self.parse_show_collation()?)
|
||||||
} 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)
|
||||||
{
|
{
|
||||||
|
@ -3841,6 +3843,11 @@ impl<'a> Parser<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse_show_collation(&mut self) -> Result<Statement, ParserError> {
|
||||||
|
let filter = self.parse_show_statement_filter()?;
|
||||||
|
Ok(Statement::ShowCollation { filter })
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_show_statement_filter(
|
pub fn parse_show_statement_filter(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> Result<Option<ShowStatementFilter>, ParserError> {
|
) -> Result<Option<ShowStatementFilter>, ParserError> {
|
||||||
|
|
|
@ -189,6 +189,12 @@ fn parse_show_extended_full() {
|
||||||
assert!(mysql_and_generic()
|
assert!(mysql_and_generic()
|
||||||
.parse_sql_statements("SHOW EXTENDED FULL CREATE TABLE mytable")
|
.parse_sql_statements("SHOW EXTENDED FULL CREATE TABLE mytable")
|
||||||
.is_err());
|
.is_err());
|
||||||
|
assert!(mysql_and_generic()
|
||||||
|
.parse_sql_statements("SHOW EXTENDED FULL COLLATION")
|
||||||
|
.is_err());
|
||||||
|
assert!(mysql_and_generic()
|
||||||
|
.parse_sql_statements("SHOW EXTENDED FULL VARIABLES")
|
||||||
|
.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -213,6 +219,28 @@ fn parse_show_create() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_show_collation() {
|
||||||
|
assert_eq!(
|
||||||
|
mysql_and_generic().verified_stmt("SHOW COLLATION"),
|
||||||
|
Statement::ShowCollation { filter: None }
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
mysql_and_generic().verified_stmt("SHOW COLLATION LIKE 'pattern'"),
|
||||||
|
Statement::ShowCollation {
|
||||||
|
filter: Some(ShowStatementFilter::Like("pattern".into())),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
mysql_and_generic().verified_stmt("SHOW COLLATION WHERE 1 = 2"),
|
||||||
|
Statement::ShowCollation {
|
||||||
|
filter: Some(ShowStatementFilter::Where(
|
||||||
|
mysql_and_generic().verified_expr("1 = 2")
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_use() {
|
fn parse_use() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue