mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-02 06:37:52 +00:00
LibSQL: Invent statement execution machinery and CREATE SCHEMA statement
This patch introduces the ability execute parsed SQL statements. The abstract AST Statement node now has a virtual 'execute' method. This method takes a Database object as parameter and returns a SQLResult object. Also introduced here is the CREATE SCHEMA statement. Tables live in a schema, and if no schema is present in a table reference the 'default' schema is implied. This schema is created if it doesn't yet exist when a Database object is created. Finally, as a proof of concept, the CREATE SCHEMA and CREATE TABLE statements received an 'execute' implementation. The CREATE TABLE method is not able to create tables created from SQL queries yet.
This commit is contained in:
committed by
Ali Mohammad Pur
parent
30691549fd
commit
1037d6b0eb
@@ -37,7 +37,11 @@ NonnullRefPtr<Statement> Parser::parse_statement()
|
||||
{
|
||||
switch (m_parser_state.m_token.type()) {
|
||||
case TokenType::Create:
|
||||
return parse_create_table_statement();
|
||||
consume();
|
||||
if (match(TokenType::Schema))
|
||||
return parse_create_schema_statement();
|
||||
else
|
||||
return parse_create_table_statement();
|
||||
case TokenType::Alter:
|
||||
return parse_alter_table_statement();
|
||||
case TokenType::Drop:
|
||||
@@ -73,10 +77,24 @@ NonnullRefPtr<Statement> Parser::parse_statement_with_expression_list(RefPtr<Com
|
||||
}
|
||||
}
|
||||
|
||||
NonnullRefPtr<CreateSchema> Parser::parse_create_schema_statement()
|
||||
{
|
||||
consume(TokenType::Schema);
|
||||
|
||||
bool is_error_if_exists = true;
|
||||
if (consume_if(TokenType::If)) {
|
||||
consume(TokenType::Not);
|
||||
consume(TokenType::Exists);
|
||||
is_error_if_exists = false;
|
||||
}
|
||||
|
||||
String schema_name = consume(TokenType::Identifier).value();
|
||||
return create_ast_node<CreateSchema>(move(schema_name), is_error_if_exists);
|
||||
}
|
||||
|
||||
NonnullRefPtr<CreateTable> Parser::parse_create_table_statement()
|
||||
{
|
||||
// https://sqlite.org/lang_createtable.html
|
||||
consume(TokenType::Create);
|
||||
|
||||
bool is_temporary = false;
|
||||
if (consume_if(TokenType::Temp) || consume_if(TokenType::Temporary))
|
||||
|
||||
Reference in New Issue
Block a user