1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:18:13 +00:00

LibSQL: Parse DROP TABLE statement

This commit is contained in:
Timothy Flynn 2021-04-20 10:16:28 -04:00 committed by Andreas Kling
parent 110cd98c0a
commit e92bffb2e3
4 changed files with 79 additions and 2 deletions

View file

@ -132,4 +132,29 @@ TEST_CASE(create_table)
validate("CREATE TABLE test ( column1 varchar(1e3) );", {}, "test", { { "column1", "varchar", { 1000 } } });
}
TEST_CASE(drop_table)
{
EXPECT(parse("DROP").is_error());
EXPECT(parse("DROP TABLE").is_error());
EXPECT(parse("DROP TABLE test").is_error());
EXPECT(parse("DROP TABLE IF test;").is_error());
auto validate = [](StringView sql, StringView expected_schema, StringView expected_table, bool expected_is_error_if_table_does_not_exist = true) {
auto result = parse(sql);
EXPECT(!result.is_error());
auto statement = result.release_value();
EXPECT(is<SQL::DropTable>(*statement));
const auto& table = static_cast<const SQL::DropTable&>(*statement);
EXPECT_EQ(table.schema_name(), expected_schema);
EXPECT_EQ(table.table_name(), expected_table);
EXPECT_EQ(table.is_error_if_table_does_not_exist(), expected_is_error_if_table_does_not_exist);
};
validate("DROP TABLE test;", {}, "test");
validate("DROP TABLE schema.test;", "schema", "test");
validate("DROP TABLE IF EXISTS test;", {}, "test", false);
}
TEST_MAIN(SqlParser)