Skip to content

Commit 8303f1c

Browse files
handle Expect table with parser method & handle end of statement in the correct place
1 parent 6a55836 commit 8303f1c

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

src/parser/mod.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -3611,23 +3611,13 @@ impl<'a> Parser<'a> {
36113611

36123612
/// Parse a UNCACHE TABLE statement
36133613
pub fn parse_uncache_table(&mut self) -> Result<Statement, ParserError> {
3614-
let has_table = self.parse_keyword(Keyword::TABLE);
3615-
if has_table {
3616-
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
3617-
let table_name = self.parse_object_name(false)?;
3618-
match self.peek_token() {
3619-
TokenWithLocation {
3620-
token: Token::EOF | Token::SemiColon,
3621-
..
3622-
} => Ok(Statement::UNCache {
3623-
table_name,
3624-
if_exists,
3625-
}),
3626-
token_loc => self.expected("`EOF` or `;`", token_loc),
3627-
}
3628-
} else {
3629-
self.expected("a `TABLE` keyword", self.peek_token())
3630-
}
3614+
self.expect_keyword(Keyword::TABLE)?;
3615+
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
3616+
let table_name = self.parse_object_name(false)?;
3617+
Ok(Statement::UNCache {
3618+
table_name,
3619+
if_exists,
3620+
})
36313621
}
36323622

36333623
/// SQLite-specific `CREATE VIRTUAL TABLE`

tests/sqlparser_common.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8451,19 +8451,19 @@ fn parse_uncache_table() {
84518451

84528452
let res = parse_sql_statements("UNCACHE TABLE 'table_name' foo");
84538453
assert_eq!(
8454-
ParserError::ParserError("Expected `EOF` or `;`, found: foo".to_string()),
8454+
ParserError::ParserError("Expected end of statement, found: foo".to_string()),
84558455
res.unwrap_err()
84568456
);
84578457

84588458
let res = parse_sql_statements("UNCACHE 'table_name' foo");
84598459
assert_eq!(
8460-
ParserError::ParserError("Expected a `TABLE` keyword, found: 'table_name'".to_string()),
8460+
ParserError::ParserError("Expected TABLE, found: 'table_name'".to_string()),
84618461
res.unwrap_err()
84628462
);
84638463

84648464
let res = parse_sql_statements("UNCACHE IF EXISTS 'table_name' foo");
84658465
assert_eq!(
8466-
ParserError::ParserError("Expected a `TABLE` keyword, found: IF".to_string()),
8466+
ParserError::ParserError("Expected TABLE, found: IF".to_string()),
84678467
res.unwrap_err()
84688468
);
84698469
}

0 commit comments

Comments
 (0)