Skip to content

Commit 30b2e48

Browse files
committed
feat: Support SHOW COLLATION (#11)
1 parent 3f8c6bc commit 30b2e48

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
@@ -886,6 +886,10 @@ pub enum Statement {
886886
db_name: Option<Ident>,
887887
filter: Option<ShowStatementFilter>,
888888
},
889+
/// SHOW COLLATION
890+
///
891+
/// Note: this is a MySQL-specific statement.
892+
ShowCollation { filter: Option<ShowStatementFilter> },
889893
/// `{ BEGIN [ TRANSACTION | WORK ] | START TRANSACTION } ...`
890894
StartTransaction { modes: Vec<TransactionMode> },
891895
/// `SET TRANSACTION ...`
@@ -1586,6 +1590,13 @@ impl fmt::Display for Statement {
15861590
}
15871591
Ok(())
15881592
}
1593+
Statement::ShowCollation { filter } => {
1594+
write!(f, "SHOW COLLATION")?;
1595+
if let Some(filter) = filter {
1596+
write!(f, " {}", filter)?;
1597+
}
1598+
Ok(())
1599+
}
15891600
Statement::StartTransaction { modes } => {
15901601
write!(f, "START TRANSACTION")?;
15911602
if !modes.is_empty() {

src/keywords.rs

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

src/parser.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,6 +3141,8 @@ impl<'a> Parser<'a> {
31413141
Err(ParserError::ParserError(
31423142
"EXTENDED/FULL are not supported with this type of SHOW query".to_string(),
31433143
))
3144+
} else if self.parse_keyword(Keyword::COLLATION) {
3145+
Ok(self.parse_show_collation()?)
31443146
} else if self.parse_one_of_keywords(&[Keyword::CREATE]).is_some() {
31453147
Ok(self.parse_show_create()?)
31463148
} else if self.parse_one_of_keywords(&[Keyword::VARIABLES]).is_some() {
@@ -3220,6 +3222,11 @@ impl<'a> Parser<'a> {
32203222
})
32213223
}
32223224

3225+
fn parse_show_collation(&mut self) -> Result<Statement, ParserError> {
3226+
let filter = self.parse_show_statement_filter()?;
3227+
Ok(Statement::ShowCollation { filter })
3228+
}
3229+
32233230
fn parse_show_statement_filter(&mut self) -> Result<Option<ShowStatementFilter>, ParserError> {
32243231
if self.parse_keyword(Keyword::LIKE) {
32253232
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_show_create() {
167189
let obj_name = ObjectName(vec![Ident::new("myident")]);

0 commit comments

Comments
 (0)