1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:27:45 +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:
Jan de Visser 2021-06-27 21:32:22 -04:00 committed by Ali Mohammad Pur
parent 30691549fd
commit 1037d6b0eb
9 changed files with 147 additions and 33 deletions

View file

@ -666,11 +666,31 @@ private:
//==================================================================================================
class Statement : public ASTNode {
public:
virtual RefPtr<SQLResult> execute(NonnullRefPtr<Database>) const { return nullptr; }
};
class ErrorStatement final : public Statement {
};
class CreateSchema : public Statement {
public:
CreateSchema(String schema_name, bool is_error_if_schema_exists)
: m_schema_name(move(schema_name))
, m_is_error_if_schema_exists(is_error_if_schema_exists)
{
}
const String& schema_name() const { return m_schema_name; }
bool is_error_if_schema_exists() const { return m_is_error_if_schema_exists; }
RefPtr<SQLResult> execute(NonnullRefPtr<Database>) const override;
private:
String m_schema_name;
bool m_is_error_if_schema_exists;
};
class CreateTable : public Statement {
public:
CreateTable(String schema_name, String table_name, RefPtr<Select> select_statement, bool is_temporary, bool is_error_if_table_exists)
@ -703,6 +723,8 @@ public:
bool is_temporary() const { return m_is_temporary; }
bool is_error_if_table_exists() const { return m_is_error_if_table_exists; }
RefPtr<SQLResult> execute(NonnullRefPtr<Database>) const override;
private:
String m_schema_name;
String m_table_name;