Support SHOW COLUMNS FROM tbl FROM db (#562)

This commit is contained in:
Alex Qyoun-ae 2022-08-11 14:42:08 +04:00 committed by GitHub
parent e2b943799a
commit 71c3ec057b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View file

@ -3739,10 +3739,16 @@ impl<'a> Parser<'a> {
let full = self.parse_keyword(Keyword::FULL); let full = self.parse_keyword(Keyword::FULL);
self.expect_one_of_keywords(&[Keyword::COLUMNS, Keyword::FIELDS])?; self.expect_one_of_keywords(&[Keyword::COLUMNS, Keyword::FIELDS])?;
self.expect_one_of_keywords(&[Keyword::FROM, Keyword::IN])?; self.expect_one_of_keywords(&[Keyword::FROM, Keyword::IN])?;
let table_name = self.parse_object_name()?; let object_name = self.parse_object_name()?;
// MySQL also supports FROM <database> here. In other words, MySQL let table_name = match self.parse_one_of_keywords(&[Keyword::FROM, Keyword::IN]) {
// allows both FROM <table> FROM <database> and FROM <database>.<table>, Some(_) => {
// while we only support the latter for now. 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()?; let filter = self.parse_show_statement_filter()?;
Ok(Statement::ShowColumns { Ok(Statement::ShowColumns {
extended, extended,

View file

@ -110,12 +110,10 @@ fn parse_show_columns() {
.one_statement_parses_to("SHOW COLUMNS IN mytable", "SHOW COLUMNS FROM mytable"); .one_statement_parses_to("SHOW COLUMNS IN mytable", "SHOW COLUMNS FROM mytable");
mysql_and_generic() mysql_and_generic()
.one_statement_parses_to("SHOW FIELDS IN mytable", "SHOW COLUMNS FROM mytable"); .one_statement_parses_to("SHOW FIELDS IN mytable", "SHOW COLUMNS FROM mytable");
mysql_and_generic().one_statement_parses_to(
// unhandled things are truly unhandled "SHOW COLUMNS FROM mytable FROM mydb",
match mysql_and_generic().parse_sql_statements("SHOW COLUMNS FROM mytable FROM mydb") { "SHOW COLUMNS FROM mydb.mytable",
Err(_) => {} );
Ok(val) => panic!("unexpected successful parse: {:?}", val),
}
} }
#[test] #[test]