Skip to content

Commit 9c9cebb

Browse files
MazterQyoumcheshkov
authored andcommitted
feat: Support SHOW COLLATION (#11)
Can drop this after rebase on commit 18881f8 "Support SHOW COLLATION (apache#564)", first released in 0.21.0
1 parent 087b628 commit 9c9cebb

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

src/ast/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,10 @@ pub enum Statement {
10271027
db_name: Option<Ident>,
10281028
filter: Option<ShowStatementFilter>,
10291029
},
1030+
/// SHOW COLLATION
1031+
///
1032+
/// Note: this is a MySQL-specific statement.
1033+
ShowCollation { filter: Option<ShowStatementFilter> },
10301034
/// USE
10311035
///
10321036
/// Note: this is a MySQL-specific statement.
@@ -1831,6 +1835,13 @@ impl fmt::Display for Statement {
18311835
}
18321836
Ok(())
18331837
}
1838+
Statement::ShowCollation { filter } => {
1839+
write!(f, "SHOW COLLATION")?;
1840+
if let Some(filter) = filter {
1841+
write!(f, " {}", filter)?;
1842+
}
1843+
Ok(())
1844+
}
18341845
Statement::Use { db_name } => {
18351846
write!(f, "USE {}", db_name)?;
18361847
Ok(())

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ define_keywords!(
129129
CLUSTER,
130130
COALESCE,
131131
COLLATE,
132+
COLLATION,
132133
COLLECT,
133134
COLUMN,
134135
COLUMNS,

src/parser.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,6 +3572,8 @@ impl<'a> Parser<'a> {
35723572
Err(ParserError::ParserError(
35733573
"EXTENDED/FULL are not supported with this type of SHOW query".to_string(),
35743574
))
3575+
} else if self.parse_keyword(Keyword::COLLATION) {
3576+
Ok(self.parse_show_collation()?)
35753577
} else if self.parse_one_of_keywords(&[Keyword::CREATE]).is_some() {
35763578
Ok(self.parse_show_create()?)
35773579
} else if self.parse_one_of_keywords(&[Keyword::VARIABLES]).is_some() {
@@ -3651,6 +3653,11 @@ impl<'a> Parser<'a> {
36513653
})
36523654
}
36533655

3656+
fn parse_show_collation(&mut self) -> Result<Statement, ParserError> {
3657+
let filter = self.parse_show_statement_filter()?;
3658+
Ok(Statement::ShowCollation { filter })
3659+
}
3660+
36543661
fn parse_show_statement_filter(&mut self) -> Result<Option<ShowStatementFilter>, ParserError> {
36553662
if self.parse_keyword(Keyword::LIKE) {
36563663
Ok(Some(ShowStatementFilter::Like(

tests/sqlparser_mysql.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,28 @@ fn parse_show_tables() {
162162
mysql_and_generic().one_statement_parses_to("SHOW TABLES IN mydb", "SHOW TABLES FROM mydb");
163163
}
164164

165+
#[test]
166+
fn parse_show_collation() {
167+
assert_eq!(
168+
mysql_and_generic().verified_stmt("SHOW COLLATION"),
169+
Statement::ShowCollation { filter: None }
170+
);
171+
assert_eq!(
172+
mysql_and_generic().verified_stmt("SHOW COLLATION LIKE 'pattern'"),
173+
Statement::ShowCollation {
174+
filter: Some(ShowStatementFilter::Like("pattern".into())),
175+
}
176+
);
177+
assert_eq!(
178+
mysql_and_generic().verified_stmt("SHOW COLLATION WHERE 1 = 2"),
179+
Statement::ShowCollation {
180+
filter: Some(ShowStatementFilter::Where(
181+
mysql_and_generic().verified_expr("1 = 2")
182+
)),
183+
}
184+
);
185+
}
186+
165187
#[test]
166188
fn parse_use() {
167189
assert_eq!(

0 commit comments

Comments
 (0)