finish VACUUM

This commit is contained in:
TcMits
2025-08-08 15:51:36 +07:00
parent 390de7153a
commit bd1e38938f

View File

@@ -500,6 +500,7 @@ impl<'a> Parser<'a> {
TokenType::TK_ATTACH,
TokenType::TK_DETACH,
TokenType::TK_PRAGMA,
TokenType::TK_VACUUM,
// add more
])?;
@@ -516,6 +517,7 @@ impl<'a> Parser<'a> {
TokenType::TK_ATTACH => self.parse_attach(),
TokenType::TK_DETACH => self.parse_detach(),
TokenType::TK_PRAGMA => self.parse_pragma(),
TokenType::TK_VACUUM => self.parse_vacuum(),
_ => unreachable!(),
}
}
@@ -2613,6 +2615,33 @@ impl<'a> Parser<'a> {
}),
}
}
fn parse_vacuum(&mut self) -> Result<Stmt, Error> {
self.eat_assert(&[TokenType::TK_VACUUM]);
let name = match self.peek()? {
Some(tok) => match tok.token_type.unwrap().fallback_id_if_ok() {
TokenType::TK_ID | TokenType::TK_STRING | TokenType::TK_INDEXED | TokenType::TK_JOIN_KW => {
Some(self.parse_nm())
}
_ => None,
},
_ => None,
};
let into = match self.peek()? {
Some(tok) if tok.token_type == Some(TokenType::TK_INTO) => {
self.eat_assert(&[TokenType::TK_INTO]);
Some(self.parse_expr(0)?)
}
_ => None,
};
Ok(Stmt::Vacuum {
name,
into,
})
}
}
#[cfg(test)]
@@ -7406,6 +7435,42 @@ mod tests {
body: None,
})],
),
// parse vacuum
(
b"VACUUM".as_slice(),
vec![Cmd::Stmt(Stmt::Vacuum {
name: None,
into: None,
})],
),
(
b"VACUUM INTO 'foo'".as_slice(),
vec![Cmd::Stmt(Stmt::Vacuum {
name: None,
into: Some(Box::new(Expr::Literal(Literal::String("'foo'".to_owned())))),
})],
),
(
b"VACUUM INTO foo".as_slice(),
vec![Cmd::Stmt(Stmt::Vacuum {
name: None,
into: Some(Box::new(Expr::Id(Name::Ident("foo".to_owned())))),
})],
),
(
b"VACUUM foo".as_slice(),
vec![Cmd::Stmt(Stmt::Vacuum {
name: Some(Name::Ident("foo".to_owned())),
into: None,
})],
),
(
b"VACUUM foo INTO 'bar'".as_slice(),
vec![Cmd::Stmt(Stmt::Vacuum {
name: Some(Name::Ident("foo".to_owned())),
into: Some(Box::new(Expr::Literal(Literal::String("'bar'".to_owned())))),
})],
),
];
for (input, expected) in test_cases {