From 71c3ec057b4701363ebecff0f2ac34b98e456f63 Mon Sep 17 00:00:00 2001 From: Alex Qyoun-ae <4062971+MazterQyou@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:42:08 +0400 Subject: [PATCH] Support `SHOW COLUMNS FROM tbl FROM db` (#562) --- src/parser.rs | 14 ++++++++++---- tests/sqlparser_mysql.rs | 10 ++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index a72529b1..e0324182 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -3739,10 +3739,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 here. In other words, MySQL - // allows both FROM FROM and FROM .
, - // 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, diff --git a/tests/sqlparser_mysql.rs b/tests/sqlparser_mysql.rs index 004b2c87..9ac775bd 100644 --- a/tests/sqlparser_mysql.rs +++ b/tests/sqlparser_mysql.rs @@ -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]