Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3611,21 +3611,13 @@ impl<'a> Parser<'a> {

/// Parse a UNCACHE TABLE statement
pub fn parse_uncache_table(&mut self) -> Result<Statement, ParserError> {
let has_table = self.parse_keyword(Keyword::TABLE);
if has_table {
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
let table_name = self.parse_object_name(false)?;
if self.peek_token().token == Token::EOF {
Ok(Statement::UNCache {
table_name,
if_exists,
})
} else {
self.expected("an `EOF`", self.peek_token())
}
} else {
self.expected("a `TABLE` keyword", self.peek_token())
}
self.expect_keyword(Keyword::TABLE)?;
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

let table_name = self.parse_object_name(false)?;
Ok(Statement::UNCache {
table_name,
if_exists,
})
}

/// SQLite-specific `CREATE VIRTUAL TABLE`
Expand Down
6 changes: 3 additions & 3 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8451,19 +8451,19 @@ fn parse_uncache_table() {

let res = parse_sql_statements("UNCACHE TABLE 'table_name' foo");
assert_eq!(
ParserError::ParserError("Expected: an `EOF`, found: foo".to_string()),
ParserError::ParserError("Expected: end of statement, found: foo".to_string()),
res.unwrap_err()
);

let res = parse_sql_statements("UNCACHE 'table_name' foo");
assert_eq!(
ParserError::ParserError("Expected: a `TABLE` keyword, found: 'table_name'".to_string()),
ParserError::ParserError("Expected: TABLE, found: 'table_name'".to_string()),
res.unwrap_err()
);

let res = parse_sql_statements("UNCACHE IF EXISTS 'table_name' foo");
assert_eq!(
ParserError::ParserError("Expected: a `TABLE` keyword, found: IF".to_string()),
ParserError::ParserError("Expected: TABLE, found: IF".to_string()),
res.unwrap_err()
);
}
Expand Down