Skip to content

Commit

Permalink
Support SHOW COLUMNS FROM tbl FROM db
Browse files Browse the repository at this point in the history
  • Loading branch information
MazterQyou committed Aug 9, 2022
1 parent 231370a commit f98ad05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 10 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3732,10 +3732,16 @@ impl<'a> Parser<'a> {
let full = self.parse_keyword(Keyword::FULL);
self.expect_one_of_keywords(&[Keyword::COLUMNS, Keyword::FIELDS])?;
self.expect_one_of_keywords(&[Keyword::FROM, Keyword::IN])?;
let table_name = self.parse_object_name()?;
// MySQL also supports FROM <database> here. In other words, MySQL
// allows both FROM <table> FROM <database> and FROM <database>.<table>,
// while we only support the latter for now.
let object_name = self.parse_object_name()?;
let table_name = match self.parse_one_of_keywords(&[Keyword::FROM, Keyword::IN]) {
Some(_) => {
let db_name = vec![self.parse_identifier()?];
let ObjectName(table_name) = object_name;
let object_name = db_name.into_iter().chain(table_name.into_iter()).collect();
ObjectName(object_name)
}
None => object_name,
};
let filter = self.parse_show_statement_filter()?;
Ok(Statement::ShowColumns {
extended,
Expand Down
10 changes: 4 additions & 6 deletions tests/sqlparser_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ fn parse_show_columns() {
.one_statement_parses_to("SHOW COLUMNS IN mytable", "SHOW COLUMNS FROM mytable");
mysql_and_generic()
.one_statement_parses_to("SHOW FIELDS IN mytable", "SHOW COLUMNS FROM mytable");

// unhandled things are truly unhandled
match mysql_and_generic().parse_sql_statements("SHOW COLUMNS FROM mytable FROM mydb") {
Err(_) => {}
Ok(val) => panic!("unexpected successful parse: {:?}", val),
}
mysql_and_generic().one_statement_parses_to(
"SHOW COLUMNS FROM mytable FROM mydb",
"SHOW COLUMNS FROM mydb.mytable",
);
}

#[test]
Expand Down

0 comments on commit f98ad05

Please sign in to comment.