Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 760
Support full SHOW TABLES syntax#563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3727,17 +3727,19 @@ impl<'a> Parser<'a> { | ||
| } | ||
| pub fn parse_show(&mut self) -> Result<Statement, ParserError> { | ||
| let extended = self.parse_keyword(Keyword::EXTENDED); | ||
| let full = self.parse_keyword(Keyword::FULL); | ||
| if self | ||
| .parse_one_of_keywords(&[ | ||
| Keyword::EXTENDED, | ||
| Keyword::FULL, | ||
| Keyword::COLUMNS, | ||
| Keyword::FIELDS, | ||
| ]) | ||
| .parse_one_of_keywords(&[Keyword::COLUMNS, Keyword::FIELDS]) | ||
| .is_some() | ||
| { | ||
| self.prev_token(); | ||
| Ok(self.parse_show_columns()?) | ||
| Ok(self.parse_show_columns(extended, full)?) | ||
| } else if self.parse_keyword(Keyword::TABLES) { | ||
| Ok(self.parse_show_tables(extended, full)?) | ||
| } else if extended || full { | ||
| Err(ParserError::ParserError( | ||
| "EXTENDED/FULL are not supported with this type of SHOW query".to_string(), | ||
| )) | ||
| } else if self.parse_one_of_keywords(&[Keyword::CREATE]).is_some() { | ||
| Ok(self.parse_show_create()?) | ||
| } else if self.parse_keyword(Keyword::VARIABLES) | ||
| @@ -3780,10 +3782,11 @@ impl<'a> Parser<'a> { | ||
| Ok(Statement::ShowCreate { obj_type, obj_name }) | ||
| } | ||
| pub fn parse_show_columns(&mut self) -> Result<Statement, ParserError> { | ||
| let extended = self.parse_keyword(Keyword::EXTENDED); | ||
| let full = self.parse_keyword(Keyword::FULL); | ||
| self.expect_one_of_keywords(&[Keyword::COLUMNS, Keyword::FIELDS])?; | ||
| pub fn parse_show_columns( | ||
| &mut self, | ||
| extended: bool, | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 nice refactoring of this into the common | ||
| full: bool, | ||
| ) -> Result<Statement, ParserError> { | ||
| self.expect_one_of_keywords(&[Keyword::FROM, Keyword::IN])?; | ||
| let object_name = self.parse_object_name()?; | ||
| let table_name = match self.parse_one_of_keywords(&[Keyword::FROM, Keyword::IN]) { | ||
| @@ -3804,6 +3807,24 @@ impl<'a> Parser<'a> { | ||
| }) | ||
| } | ||
| pub fn parse_show_tables( | ||
| &mut self, | ||
| extended: bool, | ||
| full: bool, | ||
| ) -> Result<Statement, ParserError> { | ||
| let db_name = match self.parse_one_of_keywords(&[Keyword::FROM, Keyword::IN]) { | ||
| Some(_) => Some(self.parse_identifier()?), | ||
| None => None, | ||
| }; | ||
| let filter = self.parse_show_statement_filter()?; | ||
| Ok(Statement::ShowTables { | ||
| extended, | ||
| full, | ||
| db_name, | ||
| filter, | ||
| }) | ||
| } | ||
| pub fn parse_show_statement_filter( | ||
| &mut self, | ||
| ) -> Result<Option<ShowStatementFilter>, ParserError> { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -116,6 +116,81 @@ fn parse_show_columns() { | ||
| ); | ||
| } | ||
| #[test] | ||
| fn parse_show_tables() { | ||
| assert_eq!( | ||
| mysql_and_generic().verified_stmt("SHOW TABLES"), | ||
| Statement::ShowTables { | ||
| extended: false, | ||
| full: false, | ||
| db_name: None, | ||
| filter: None, | ||
| } | ||
| ); | ||
| assert_eq!( | ||
| mysql_and_generic().verified_stmt("SHOW TABLES FROM mydb"), | ||
| Statement::ShowTables { | ||
| extended: false, | ||
| full: false, | ||
| db_name: Some(Ident::new("mydb")), | ||
| filter: None, | ||
| } | ||
| ); | ||
| assert_eq!( | ||
| mysql_and_generic().verified_stmt("SHOW EXTENDED TABLES"), | ||
| Statement::ShowTables { | ||
| extended: true, | ||
| full: false, | ||
| db_name: None, | ||
| filter: None, | ||
| } | ||
| ); | ||
| assert_eq!( | ||
| mysql_and_generic().verified_stmt("SHOW FULL TABLES"), | ||
| Statement::ShowTables { | ||
| extended: false, | ||
| full: true, | ||
| db_name: None, | ||
| filter: None, | ||
| } | ||
| ); | ||
| assert_eq!( | ||
| mysql_and_generic().verified_stmt("SHOW TABLES LIKE 'pattern'"), | ||
| Statement::ShowTables { | ||
| extended: false, | ||
| full: false, | ||
| db_name: None, | ||
| filter: Some(ShowStatementFilter::Like("pattern".into())), | ||
| } | ||
| ); | ||
| assert_eq!( | ||
| mysql_and_generic().verified_stmt("SHOW TABLES WHERE 1 = 2"), | ||
| Statement::ShowTables { | ||
| extended: false, | ||
| full: false, | ||
| db_name: None, | ||
| filter: Some(ShowStatementFilter::Where( | ||
| mysql_and_generic().verified_expr("1 = 2") | ||
| )), | ||
| } | ||
| ); | ||
| mysql_and_generic().one_statement_parses_to("SHOW TABLES IN mydb", "SHOW TABLES FROM mydb"); | ||
| } | ||
| #[test] | ||
| fn parse_show_extended_full() { | ||
| assert!(mysql_and_generic() | ||
| .parse_sql_statements("SHOW EXTENDED FULL TABLES") | ||
| .is_ok()); | ||
| assert!(mysql_and_generic() | ||
| .parse_sql_statements("SHOW EXTENDED FULL COLUMNS FROM mytable") | ||
| .is_ok()); | ||
| // SHOW EXTENDED/FULL can only be used with COLUMNS and TABLES | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great tests 🏅 | ||
| assert!(mysql_and_generic() | ||
| .parse_sql_statements("SHOW EXTENDED FULL CREATE TABLE mytable") | ||
| .is_err()); | ||
| } | ||
| #[test] | ||
| fn parse_show_create() { | ||
| let obj_name = ObjectName(vec![Ident::new("myident")]); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed and this appears to match https://dev.mysql.com/doc/refman/8.0/en/show-tables.html