1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:37:35 +00:00

LibSQL: Parse CREATE TABLE statements with a nested SELECT statement

This commit is contained in:
Timothy Flynn 2021-04-23 13:37:47 -04:00 committed by Andreas Kling
parent 99b38aa3fa
commit cb943a2179
3 changed files with 33 additions and 1 deletions

View file

@ -45,6 +45,8 @@ TEST_CASE(create_table)
EXPECT(parse("CREATE TABLE test ( column1 )").is_error());
EXPECT(parse("CREATE TABLE IF test ( column1 );").is_error());
EXPECT(parse("CREATE TABLE IF NOT test ( column1 );").is_error());
EXPECT(parse("CREATE TABLE AS;").is_error());
EXPECT(parse("CREATE TABLE AS SELECT;").is_error());
EXPECT(parse("CREATE TABLE test ( column1 varchar()").is_error());
EXPECT(parse("CREATE TABLE test ( column1 varchar(abc)").is_error());
EXPECT(parse("CREATE TABLE test ( column1 varchar(123 )").is_error());
@ -55,6 +57,8 @@ TEST_CASE(create_table)
EXPECT(parse("CREATE TABLE test ( column1 varchar(0x) )").is_error());
EXPECT(parse("CREATE TABLE test ( column1 varchar(0xzzz) )").is_error());
EXPECT(parse("WITH table AS () CREATE TABLE test ( column1 );").is_error());
EXPECT(parse("CREATE TABLE test ( column1 int ) AS SELECT * FROM table;").is_error());
EXPECT(parse("CREATE TABLE test AS SELECT * FROM table ( column1 int ) ;").is_error());
struct Column {
StringView name;
@ -75,6 +79,13 @@ TEST_CASE(create_table)
EXPECT_EQ(table.is_temporary(), expected_is_temporary);
EXPECT_EQ(table.is_error_if_table_exists(), expected_is_error_if_table_exists);
bool expect_select_statement = expected_columns.is_empty();
EXPECT_EQ(table.has_selection(), expect_select_statement);
EXPECT_EQ(table.has_columns(), !expect_select_statement);
const auto& select_statement = table.select_statement();
EXPECT_EQ(select_statement.is_null(), !expect_select_statement);
const auto& columns = table.columns();
EXPECT_EQ(columns.size(), expected_columns.size());
@ -103,6 +114,8 @@ TEST_CASE(create_table)
validate("CREATE TEMPORARY TABLE test ( column1 );", {}, "test", { { "column1", "BLOB" } }, true, true);
validate("CREATE TABLE IF NOT EXISTS test ( column1 );", {}, "test", { { "column1", "BLOB" } }, false, false);
validate("CREATE TABLE test AS SELECT * FROM table;", {}, "test", {});
validate("CREATE TABLE test ( column1 int );", {}, "test", { { "column1", "int" } });
validate("CREATE TABLE test ( column1 varchar );", {}, "test", { { "column1", "varchar" } });
validate("CREATE TABLE test ( column1 varchar(255) );", {}, "test", { { "column1", "varchar", { 255 } } });