mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
LibSQL+SQLServer: Bare bones INSERT and SELECT statements
This patch provides very basic, bare bones implementations of the INSERT and SELECT statements. They are *very* limited: - The only variant of the INSERT statement that currently works is SELECT INTO schema.table (column1, column2, ....) VALUES (value11, value21, ...), (value12, value22, ...), ... where the values are literals. - The SELECT statement is even more limited, and is only provided to allow verification of the INSERT statement. The only form implemented is: SELECT * FROM schema.table These statements required a bit of change in the Statement::execute API. Originally execute only received a Database object as parameter. This is not enough; we now pass an ExecutionContext object which contains the Database, the current result set, and the last Tuple read from the database. This object will undoubtedly evolve over time. This API change dragged SQLServer::SQLStatement into the patch. Another API addition is Expression::evaluate. This method is, unsurprisingly, used to evaluate expressions, like the values in the INSERT statement. Finally, a new test file is added: TestSqlStatementExecution, which tests the currently implemented statements. As the number and flavour of implemented statements grows, this test file will probably have to be restructured.
This commit is contained in:
parent
230118c4b2
commit
d074a601df
12 changed files with 329 additions and 16 deletions
|
@ -295,7 +295,15 @@ private:
|
|||
// Expressions
|
||||
//==================================================================================================
|
||||
|
||||
struct ExecutionContext {
|
||||
NonnullRefPtr<Database> database;
|
||||
RefPtr<SQLResult> result { nullptr };
|
||||
Tuple current_row {};
|
||||
};
|
||||
|
||||
class Expression : public ASTNode {
|
||||
public:
|
||||
virtual Value evaluate(ExecutionContext&) const;
|
||||
};
|
||||
|
||||
class ErrorExpression final : public Expression {
|
||||
|
@ -309,6 +317,7 @@ public:
|
|||
}
|
||||
|
||||
double value() const { return m_value; }
|
||||
virtual Value evaluate(ExecutionContext&) const override;
|
||||
|
||||
private:
|
||||
double m_value;
|
||||
|
@ -322,6 +331,7 @@ public:
|
|||
}
|
||||
|
||||
const String& value() const { return m_value; }
|
||||
virtual Value evaluate(ExecutionContext&) const override;
|
||||
|
||||
private:
|
||||
String m_value;
|
||||
|
@ -341,11 +351,14 @@ private:
|
|||
};
|
||||
|
||||
class NullLiteral : public Expression {
|
||||
public:
|
||||
virtual Value evaluate(ExecutionContext&) const override;
|
||||
};
|
||||
|
||||
class NestedExpression : public Expression {
|
||||
public:
|
||||
const NonnullRefPtr<Expression>& expression() const { return m_expression; }
|
||||
virtual Value evaluate(ExecutionContext&) const override;
|
||||
|
||||
protected:
|
||||
explicit NestedExpression(NonnullRefPtr<Expression> expression)
|
||||
|
@ -439,6 +452,7 @@ public:
|
|||
}
|
||||
|
||||
UnaryOperator type() const { return m_type; }
|
||||
virtual Value evaluate(ExecutionContext&) const override;
|
||||
|
||||
private:
|
||||
UnaryOperator m_type;
|
||||
|
@ -488,6 +502,7 @@ public:
|
|||
}
|
||||
|
||||
const NonnullRefPtrVector<Expression>& expressions() const { return m_expressions; }
|
||||
virtual Value evaluate(ExecutionContext&) const override;
|
||||
|
||||
private:
|
||||
NonnullRefPtrVector<Expression> m_expressions;
|
||||
|
@ -667,7 +682,7 @@ private:
|
|||
|
||||
class Statement : public ASTNode {
|
||||
public:
|
||||
virtual RefPtr<SQLResult> execute(NonnullRefPtr<Database>) const { return nullptr; }
|
||||
virtual RefPtr<SQLResult> execute(ExecutionContext&) const { return nullptr; }
|
||||
};
|
||||
|
||||
class ErrorStatement final : public Statement {
|
||||
|
@ -684,7 +699,7 @@ public:
|
|||
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;
|
||||
RefPtr<SQLResult> execute(ExecutionContext&) const override;
|
||||
|
||||
private:
|
||||
String m_schema_name;
|
||||
|
@ -723,7 +738,7 @@ 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;
|
||||
RefPtr<SQLResult> execute(ExecutionContext&) const override;
|
||||
|
||||
private:
|
||||
String m_schema_name;
|
||||
|
@ -886,6 +901,8 @@ public:
|
|||
bool has_selection() const { return !m_select_statement.is_null(); }
|
||||
const RefPtr<Select>& select_statement() const { return m_select_statement; }
|
||||
|
||||
RefPtr<SQLResult> execute(ExecutionContext&) const;
|
||||
|
||||
private:
|
||||
RefPtr<CommonTableExpressionList> m_common_table_expression_list;
|
||||
ConflictResolution m_conflict_resolution;
|
||||
|
@ -977,6 +994,7 @@ public:
|
|||
const RefPtr<GroupByClause>& group_by_clause() const { return m_group_by_clause; }
|
||||
const NonnullRefPtrVector<OrderingTerm>& ordering_term_list() const { return m_ordering_term_list; }
|
||||
const RefPtr<LimitClause>& limit_clause() const { return m_limit_clause; }
|
||||
RefPtr<SQLResult> execute(ExecutionContext&) const override;
|
||||
|
||||
private:
|
||||
RefPtr<CommonTableExpressionList> m_common_table_expression_list;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue