2021-04-18 17:38:38 -04:00
|
|
|
/*
|
2022-01-31 13:07:22 -05:00
|
|
|
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
|
2021-12-06 15:30:38 +02:00
|
|
|
* Copyright (c) 2021, Mahmoud Mandour <ma.mandourr@gmail.com>
|
2022-03-04 13:22:31 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2021-04-18 17:38:38 -04:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-04-18 17:38:38 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
#include <AK/DeprecatedString.h>
|
2021-04-18 17:38:38 -04:00
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
|
|
|
#include <AK/NonnullRefPtrVector.h>
|
|
|
|
|
#include <AK/RefCounted.h>
|
2021-04-20 17:49:26 -04:00
|
|
|
#include <AK/RefPtr.h>
|
2021-06-21 10:57:44 -04:00
|
|
|
#include <LibSQL/AST/Token.h>
|
2021-04-20 17:49:26 -04:00
|
|
|
#include <LibSQL/Forward.h>
|
2022-02-09 16:02:49 -05:00
|
|
|
#include <LibSQL/Result.h>
|
2022-02-10 14:43:00 -05:00
|
|
|
#include <LibSQL/ResultSet.h>
|
2021-06-27 21:00:08 -04:00
|
|
|
#include <LibSQL/Type.h>
|
2021-04-18 17:38:38 -04:00
|
|
|
|
2021-06-21 10:57:44 -04:00
|
|
|
namespace SQL::AST {
|
2021-04-18 17:38:38 -04:00
|
|
|
|
|
|
|
|
template<class T, class... Args>
|
|
|
|
|
static inline NonnullRefPtr<T>
|
|
|
|
|
create_ast_node(Args&&... args)
|
|
|
|
|
{
|
2021-04-23 16:46:57 +02:00
|
|
|
return adopt_ref(*new T(forward<Args>(args)...));
|
2021-04-18 17:38:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ASTNode : public RefCounted<ASTNode> {
|
|
|
|
|
public:
|
2022-03-04 13:22:31 -07:00
|
|
|
virtual ~ASTNode() = default;
|
2021-04-18 17:38:38 -04:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
ASTNode() = default;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-20 17:49:26 -04:00
|
|
|
//==================================================================================================
|
|
|
|
|
// Language types
|
|
|
|
|
//==================================================================================================
|
2021-04-18 17:38:38 -04:00
|
|
|
|
|
|
|
|
class SignedNumber final : public ASTNode {
|
|
|
|
|
public:
|
|
|
|
|
explicit SignedNumber(double value)
|
|
|
|
|
: m_value(value)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double value() const { return m_value; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
double m_value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TypeName : public ASTNode {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
TypeName(DeprecatedString name, NonnullRefPtrVector<SignedNumber> signed_numbers)
|
2021-04-18 17:38:38 -04:00
|
|
|
: m_name(move(name))
|
|
|
|
|
, m_signed_numbers(move(signed_numbers))
|
|
|
|
|
{
|
|
|
|
|
VERIFY(m_signed_numbers.size() <= 2);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& name() const { return m_name; }
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtrVector<SignedNumber> const& signed_numbers() const { return m_signed_numbers; }
|
2021-04-18 17:38:38 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_name;
|
2021-04-18 17:38:38 -04:00
|
|
|
NonnullRefPtrVector<SignedNumber> m_signed_numbers;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ColumnDefinition : public ASTNode {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
ColumnDefinition(DeprecatedString name, NonnullRefPtr<TypeName> type_name)
|
2021-04-18 17:38:38 -04:00
|
|
|
: m_name(move(name))
|
|
|
|
|
, m_type_name(move(type_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& name() const { return m_name; }
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<TypeName> const& type_name() const { return m_type_name; }
|
2021-04-18 17:38:38 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_name;
|
2021-04-18 17:38:38 -04:00
|
|
|
NonnullRefPtr<TypeName> m_type_name;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-21 14:13:05 -04:00
|
|
|
class CommonTableExpression : public ASTNode {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
CommonTableExpression(DeprecatedString table_name, Vector<DeprecatedString> column_names, NonnullRefPtr<Select> select_statement)
|
2021-04-21 14:13:05 -04:00
|
|
|
: m_table_name(move(table_name))
|
|
|
|
|
, m_column_names(move(column_names))
|
2021-04-23 14:45:56 -04:00
|
|
|
, m_select_statement(move(select_statement))
|
2021-04-21 14:13:05 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& table_name() const { return m_table_name; }
|
|
|
|
|
Vector<DeprecatedString> const& column_names() const { return m_column_names; }
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<Select> const& select_statement() const { return m_select_statement; }
|
2021-04-21 14:13:05 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_table_name;
|
|
|
|
|
Vector<DeprecatedString> m_column_names;
|
2021-04-23 14:45:56 -04:00
|
|
|
NonnullRefPtr<Select> m_select_statement;
|
2021-04-21 14:13:05 -04:00
|
|
|
};
|
|
|
|
|
|
2021-04-21 16:56:19 -04:00
|
|
|
class CommonTableExpressionList : public ASTNode {
|
|
|
|
|
public:
|
|
|
|
|
CommonTableExpressionList(bool recursive, NonnullRefPtrVector<CommonTableExpression> common_table_expressions)
|
|
|
|
|
: m_recursive(recursive)
|
|
|
|
|
, m_common_table_expressions(move(common_table_expressions))
|
|
|
|
|
{
|
|
|
|
|
VERIFY(!m_common_table_expressions.is_empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool recursive() const { return m_recursive; }
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtrVector<CommonTableExpression> const& common_table_expressions() const { return m_common_table_expressions; }
|
2021-04-21 16:56:19 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool m_recursive;
|
|
|
|
|
NonnullRefPtrVector<CommonTableExpression> m_common_table_expressions;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-21 14:13:05 -04:00
|
|
|
class QualifiedTableName : public ASTNode {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
QualifiedTableName(DeprecatedString schema_name, DeprecatedString table_name, DeprecatedString alias)
|
2021-04-21 14:13:05 -04:00
|
|
|
: m_schema_name(move(schema_name))
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
, m_alias(move(alias))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& schema_name() const { return m_schema_name; }
|
|
|
|
|
DeprecatedString const& table_name() const { return m_table_name; }
|
|
|
|
|
DeprecatedString const& alias() const { return m_alias; }
|
2021-04-21 14:13:05 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_schema_name;
|
|
|
|
|
DeprecatedString m_table_name;
|
|
|
|
|
DeprecatedString m_alias;
|
2021-04-21 14:13:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ReturningClause : public ASTNode {
|
|
|
|
|
public:
|
|
|
|
|
struct ColumnClause {
|
|
|
|
|
NonnullRefPtr<Expression> expression;
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString column_alias;
|
2021-04-21 14:13:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ReturningClause() = default;
|
|
|
|
|
|
|
|
|
|
explicit ReturningClause(Vector<ColumnClause> columns)
|
|
|
|
|
: m_columns(move(columns))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool return_all_columns() const { return m_columns.is_empty(); };
|
2022-04-01 20:58:27 +03:00
|
|
|
Vector<ColumnClause> const& columns() const { return m_columns; }
|
2021-04-21 14:13:05 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Vector<ColumnClause> m_columns;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-22 10:11:17 -04:00
|
|
|
enum class ResultType {
|
|
|
|
|
All,
|
|
|
|
|
Table,
|
|
|
|
|
Expression,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ResultColumn : public ASTNode {
|
|
|
|
|
public:
|
|
|
|
|
ResultColumn() = default;
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
explicit ResultColumn(DeprecatedString table_name)
|
2021-04-22 10:11:17 -04:00
|
|
|
: m_type(ResultType::Table)
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
ResultColumn(NonnullRefPtr<Expression> expression, DeprecatedString column_alias)
|
2021-04-22 10:11:17 -04:00
|
|
|
: m_type(ResultType::Expression)
|
|
|
|
|
, m_expression(move(expression))
|
|
|
|
|
, m_column_alias(move(column_alias))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResultType type() const { return m_type; }
|
|
|
|
|
|
|
|
|
|
bool select_from_table() const { return !m_table_name.is_null(); }
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& table_name() const { return m_table_name; }
|
2021-04-22 10:11:17 -04:00
|
|
|
|
|
|
|
|
bool select_from_expression() const { return !m_expression.is_null(); }
|
2022-04-01 20:58:27 +03:00
|
|
|
RefPtr<Expression> const& expression() const { return m_expression; }
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& column_alias() const { return m_column_alias; }
|
2021-04-22 10:11:17 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ResultType m_type { ResultType::All };
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_table_name {};
|
2021-04-22 10:11:17 -04:00
|
|
|
|
|
|
|
|
RefPtr<Expression> m_expression {};
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_column_alias {};
|
2021-04-22 10:11:17 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class GroupByClause : public ASTNode {
|
|
|
|
|
public:
|
|
|
|
|
GroupByClause(NonnullRefPtrVector<Expression> group_by_list, RefPtr<Expression> having_clause)
|
|
|
|
|
: m_group_by_list(move(group_by_list))
|
|
|
|
|
, m_having_clause(move(having_clause))
|
|
|
|
|
{
|
|
|
|
|
VERIFY(!m_group_by_list.is_empty());
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtrVector<Expression> const& group_by_list() const { return m_group_by_list; }
|
|
|
|
|
RefPtr<Expression> const& having_clause() const { return m_having_clause; }
|
2021-04-22 10:11:17 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtrVector<Expression> m_group_by_list;
|
|
|
|
|
RefPtr<Expression> m_having_clause;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TableOrSubquery : public ASTNode {
|
|
|
|
|
public:
|
|
|
|
|
TableOrSubquery() = default;
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
TableOrSubquery(DeprecatedString schema_name, DeprecatedString table_name, DeprecatedString table_alias)
|
2021-04-22 10:11:17 -04:00
|
|
|
: m_is_table(true)
|
|
|
|
|
, m_schema_name(move(schema_name))
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
, m_table_alias(move(table_alias))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
explicit TableOrSubquery(NonnullRefPtrVector<TableOrSubquery> subqueries)
|
|
|
|
|
: m_is_subquery(!subqueries.is_empty())
|
|
|
|
|
, m_subqueries(move(subqueries))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_table() const { return m_is_table; }
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& schema_name() const { return m_schema_name; }
|
|
|
|
|
DeprecatedString const& table_name() const { return m_table_name; }
|
|
|
|
|
DeprecatedString const& table_alias() const { return m_table_alias; }
|
2021-04-22 10:11:17 -04:00
|
|
|
|
|
|
|
|
bool is_subquery() const { return m_is_subquery; }
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtrVector<TableOrSubquery> const& subqueries() const { return m_subqueries; }
|
2021-04-22 10:11:17 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool m_is_table { false };
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_schema_name {};
|
|
|
|
|
DeprecatedString m_table_name {};
|
|
|
|
|
DeprecatedString m_table_alias {};
|
2021-04-22 10:11:17 -04:00
|
|
|
|
|
|
|
|
bool m_is_subquery { false };
|
|
|
|
|
NonnullRefPtrVector<TableOrSubquery> m_subqueries {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class OrderingTerm : public ASTNode {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
OrderingTerm(NonnullRefPtr<Expression> expression, DeprecatedString collation_name, Order order, Nulls nulls)
|
2021-04-22 10:11:17 -04:00
|
|
|
: m_expression(move(expression))
|
|
|
|
|
, m_collation_name(move(collation_name))
|
|
|
|
|
, m_order(order)
|
|
|
|
|
, m_nulls(nulls)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<Expression> const& expression() const { return m_expression; }
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& collation_name() const { return m_collation_name; }
|
2021-04-22 10:11:17 -04:00
|
|
|
Order order() const { return m_order; }
|
|
|
|
|
Nulls nulls() const { return m_nulls; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<Expression> m_expression;
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_collation_name;
|
2021-04-22 10:11:17 -04:00
|
|
|
Order m_order;
|
|
|
|
|
Nulls m_nulls;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class LimitClause : public ASTNode {
|
|
|
|
|
public:
|
|
|
|
|
LimitClause(NonnullRefPtr<Expression> limit_expression, RefPtr<Expression> offset_expression)
|
|
|
|
|
: m_limit_expression(move(limit_expression))
|
|
|
|
|
, m_offset_expression(move(offset_expression))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<Expression> const& limit_expression() const { return m_limit_expression; }
|
|
|
|
|
RefPtr<Expression> const& offset_expression() const { return m_offset_expression; }
|
2021-04-22 10:11:17 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<Expression> m_limit_expression;
|
|
|
|
|
RefPtr<Expression> m_offset_expression;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-20 17:49:26 -04:00
|
|
|
//==================================================================================================
|
|
|
|
|
// Expressions
|
|
|
|
|
//==================================================================================================
|
|
|
|
|
|
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.
2021-07-19 19:48:46 -04:00
|
|
|
struct ExecutionContext {
|
|
|
|
|
NonnullRefPtr<Database> database;
|
2022-12-01 22:20:55 -05:00
|
|
|
Statement const* statement { nullptr };
|
|
|
|
|
Span<Value const> placeholder_values {};
|
2021-09-16 22:29:19 +02:00
|
|
|
Tuple* current_row { nullptr };
|
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.
2021-07-19 19:48:46 -04:00
|
|
|
};
|
|
|
|
|
|
2021-04-20 17:49:26 -04:00
|
|
|
class Expression : public ASTNode {
|
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.
2021-07-19 19:48:46 -04:00
|
|
|
public:
|
2022-02-10 17:58:55 -05:00
|
|
|
virtual ResultOr<Value> evaluate(ExecutionContext&) const
|
|
|
|
|
{
|
|
|
|
|
return Result { SQLCommand::Unknown, SQLErrorCode::NotYetImplemented };
|
|
|
|
|
}
|
2021-04-20 17:49:26 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ErrorExpression final : public Expression {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NumericLiteral : public Expression {
|
|
|
|
|
public:
|
|
|
|
|
explicit NumericLiteral(double value)
|
|
|
|
|
: m_value(value)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double value() const { return m_value; }
|
2022-02-10 07:46:36 -05:00
|
|
|
virtual ResultOr<Value> evaluate(ExecutionContext&) const override;
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
double m_value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class StringLiteral : public Expression {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
explicit StringLiteral(DeprecatedString value)
|
2021-04-20 17:49:26 -04:00
|
|
|
: m_value(move(value))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& value() const { return m_value; }
|
2022-02-10 07:46:36 -05:00
|
|
|
virtual ResultOr<Value> evaluate(ExecutionContext&) const override;
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_value;
|
2021-04-20 17:49:26 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class BlobLiteral : public Expression {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
explicit BlobLiteral(DeprecatedString value)
|
2021-04-20 17:49:26 -04:00
|
|
|
: m_value(move(value))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& value() const { return m_value; }
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_value;
|
2021-04-20 17:49:26 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NullLiteral : public Expression {
|
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.
2021-07-19 19:48:46 -04:00
|
|
|
public:
|
2022-02-10 07:46:36 -05:00
|
|
|
virtual ResultOr<Value> evaluate(ExecutionContext&) const override;
|
2021-04-20 17:49:26 -04:00
|
|
|
};
|
|
|
|
|
|
2022-12-01 22:20:55 -05:00
|
|
|
class Placeholder : public Expression {
|
|
|
|
|
public:
|
|
|
|
|
explicit Placeholder(size_t parameter_index)
|
|
|
|
|
: m_parameter_index(parameter_index)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t parameter_index() const { return m_parameter_index; }
|
|
|
|
|
|
|
|
|
|
virtual ResultOr<Value> evaluate(ExecutionContext&) const override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
size_t m_parameter_index { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-20 17:49:26 -04:00
|
|
|
class NestedExpression : public Expression {
|
|
|
|
|
public:
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<Expression> const& expression() const { return m_expression; }
|
2022-02-10 07:46:36 -05:00
|
|
|
virtual ResultOr<Value> evaluate(ExecutionContext&) const override;
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit NestedExpression(NonnullRefPtr<Expression> expression)
|
|
|
|
|
: m_expression(move(expression))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<Expression> m_expression;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NestedDoubleExpression : public Expression {
|
|
|
|
|
public:
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<Expression> const& lhs() const { return m_lhs; }
|
|
|
|
|
NonnullRefPtr<Expression> const& rhs() const { return m_rhs; }
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
NestedDoubleExpression(NonnullRefPtr<Expression> lhs, NonnullRefPtr<Expression> rhs)
|
|
|
|
|
: m_lhs(move(lhs))
|
|
|
|
|
, m_rhs(move(rhs))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<Expression> m_lhs;
|
|
|
|
|
NonnullRefPtr<Expression> m_rhs;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class InvertibleNestedExpression : public NestedExpression {
|
|
|
|
|
public:
|
|
|
|
|
bool invert_expression() const { return m_invert_expression; }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
InvertibleNestedExpression(NonnullRefPtr<Expression> expression, bool invert_expression)
|
|
|
|
|
: NestedExpression(move(expression))
|
|
|
|
|
, m_invert_expression(invert_expression)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool m_invert_expression;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class InvertibleNestedDoubleExpression : public NestedDoubleExpression {
|
|
|
|
|
public:
|
|
|
|
|
bool invert_expression() const { return m_invert_expression; }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
InvertibleNestedDoubleExpression(NonnullRefPtr<Expression> lhs, NonnullRefPtr<Expression> rhs, bool invert_expression)
|
|
|
|
|
: NestedDoubleExpression(move(lhs), move(rhs))
|
|
|
|
|
, m_invert_expression(invert_expression)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool m_invert_expression;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ColumnNameExpression : public Expression {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
ColumnNameExpression(DeprecatedString schema_name, DeprecatedString table_name, DeprecatedString column_name)
|
2021-04-20 17:49:26 -04:00
|
|
|
: m_schema_name(move(schema_name))
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
, m_column_name(move(column_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& schema_name() const { return m_schema_name; }
|
|
|
|
|
DeprecatedString const& table_name() const { return m_table_name; }
|
|
|
|
|
DeprecatedString const& column_name() const { return m_column_name; }
|
2022-02-10 07:46:36 -05:00
|
|
|
virtual ResultOr<Value> evaluate(ExecutionContext&) const override;
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_schema_name;
|
|
|
|
|
DeprecatedString m_table_name;
|
|
|
|
|
DeprecatedString m_column_name;
|
2021-04-20 17:49:26 -04:00
|
|
|
};
|
|
|
|
|
|
2021-10-23 10:46:33 -04:00
|
|
|
#define __enum_UnaryOperator(S) \
|
|
|
|
|
S(Minus, "-") \
|
|
|
|
|
S(Plus, "+") \
|
|
|
|
|
S(BitwiseNot, "~") \
|
|
|
|
|
S(Not, "NOT")
|
|
|
|
|
|
2021-04-20 17:49:26 -04:00
|
|
|
enum class UnaryOperator {
|
2021-10-23 10:46:33 -04:00
|
|
|
#undef __UnaryOperator
|
|
|
|
|
#define __UnaryOperator(code, name) code,
|
|
|
|
|
__enum_UnaryOperator(__UnaryOperator)
|
|
|
|
|
#undef __UnaryOperator
|
2021-04-20 17:49:26 -04:00
|
|
|
};
|
|
|
|
|
|
2021-10-23 10:46:33 -04:00
|
|
|
constexpr char const* UnaryOperator_name(UnaryOperator op)
|
|
|
|
|
{
|
|
|
|
|
switch (op) {
|
|
|
|
|
#undef __UnaryOperator
|
|
|
|
|
#define __UnaryOperator(code, name) \
|
|
|
|
|
case UnaryOperator::code: \
|
|
|
|
|
return name;
|
|
|
|
|
__enum_UnaryOperator(__UnaryOperator)
|
|
|
|
|
#undef __UnaryOperator
|
|
|
|
|
default : VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-20 17:49:26 -04:00
|
|
|
class UnaryOperatorExpression : public NestedExpression {
|
|
|
|
|
public:
|
|
|
|
|
UnaryOperatorExpression(UnaryOperator type, NonnullRefPtr<Expression> expression)
|
|
|
|
|
: NestedExpression(move(expression))
|
|
|
|
|
, m_type(type)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UnaryOperator type() const { return m_type; }
|
2022-02-10 07:46:36 -05:00
|
|
|
virtual ResultOr<Value> evaluate(ExecutionContext&) const override;
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
UnaryOperator m_type;
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-23 10:46:33 -04:00
|
|
|
// Note: These are in order of highest-to-lowest operator precedence.
|
|
|
|
|
#define __enum_BinaryOperator(S) \
|
|
|
|
|
S(Concatenate, "||") \
|
|
|
|
|
S(Multiplication, "*") \
|
|
|
|
|
S(Division, "/") \
|
|
|
|
|
S(Modulo, "%") \
|
|
|
|
|
S(Plus, "+") \
|
|
|
|
|
S(Minus, "-") \
|
|
|
|
|
S(ShiftLeft, "<<") \
|
|
|
|
|
S(ShiftRight, ">>") \
|
|
|
|
|
S(BitwiseAnd, "&") \
|
|
|
|
|
S(BitwiseOr, "|") \
|
|
|
|
|
S(LessThan, "<") \
|
|
|
|
|
S(LessThanEquals, "<=") \
|
|
|
|
|
S(GreaterThan, ">") \
|
|
|
|
|
S(GreaterThanEquals, ">=") \
|
|
|
|
|
S(Equals, "=") \
|
|
|
|
|
S(NotEquals, "!=") \
|
|
|
|
|
S(And, "and") \
|
|
|
|
|
S(Or, "or")
|
|
|
|
|
|
2021-04-20 17:49:26 -04:00
|
|
|
enum class BinaryOperator {
|
2021-10-23 10:46:33 -04:00
|
|
|
#undef __BinaryOperator
|
|
|
|
|
#define __BinaryOperator(code, name) code,
|
|
|
|
|
__enum_BinaryOperator(__BinaryOperator)
|
|
|
|
|
#undef __BinaryOperator
|
2021-04-20 17:49:26 -04:00
|
|
|
};
|
|
|
|
|
|
2021-10-23 10:46:33 -04:00
|
|
|
constexpr char const* BinaryOperator_name(BinaryOperator op)
|
|
|
|
|
{
|
|
|
|
|
switch (op) {
|
|
|
|
|
#undef __BinaryOperator
|
|
|
|
|
#define __BinaryOperator(code, name) \
|
|
|
|
|
case BinaryOperator::code: \
|
|
|
|
|
return name;
|
|
|
|
|
__enum_BinaryOperator(__BinaryOperator)
|
|
|
|
|
#undef __BinaryOperator
|
|
|
|
|
default : VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-20 17:49:26 -04:00
|
|
|
class BinaryOperatorExpression : public NestedDoubleExpression {
|
|
|
|
|
public:
|
|
|
|
|
BinaryOperatorExpression(BinaryOperator type, NonnullRefPtr<Expression> lhs, NonnullRefPtr<Expression> rhs)
|
|
|
|
|
: NestedDoubleExpression(move(lhs), move(rhs))
|
|
|
|
|
, m_type(type)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BinaryOperator type() const { return m_type; }
|
2022-02-10 07:46:36 -05:00
|
|
|
virtual ResultOr<Value> evaluate(ExecutionContext&) const override;
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
BinaryOperator m_type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ChainedExpression : public Expression {
|
|
|
|
|
public:
|
|
|
|
|
explicit ChainedExpression(NonnullRefPtrVector<Expression> expressions)
|
|
|
|
|
: m_expressions(move(expressions))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtrVector<Expression> const& expressions() const { return m_expressions; }
|
2022-02-10 07:46:36 -05:00
|
|
|
virtual ResultOr<Value> evaluate(ExecutionContext&) const override;
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtrVector<Expression> m_expressions;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CastExpression : public NestedExpression {
|
|
|
|
|
public:
|
|
|
|
|
CastExpression(NonnullRefPtr<Expression> expression, NonnullRefPtr<TypeName> type_name)
|
|
|
|
|
: NestedExpression(move(expression))
|
|
|
|
|
, m_type_name(move(type_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<TypeName> const& type_name() const { return m_type_name; }
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<TypeName> m_type_name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CaseExpression : public Expression {
|
|
|
|
|
public:
|
|
|
|
|
struct WhenThenClause {
|
|
|
|
|
NonnullRefPtr<Expression> when;
|
|
|
|
|
NonnullRefPtr<Expression> then;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CaseExpression(RefPtr<Expression> case_expression, Vector<WhenThenClause> when_then_clauses, RefPtr<Expression> else_expression)
|
|
|
|
|
: m_case_expression(case_expression)
|
|
|
|
|
, m_when_then_clauses(when_then_clauses)
|
|
|
|
|
, m_else_expression(else_expression)
|
|
|
|
|
{
|
|
|
|
|
VERIFY(!m_when_then_clauses.is_empty());
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
RefPtr<Expression> const& case_expression() const { return m_case_expression; }
|
|
|
|
|
Vector<WhenThenClause> const& when_then_clauses() const { return m_when_then_clauses; }
|
|
|
|
|
RefPtr<Expression> const& else_expression() const { return m_else_expression; }
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
RefPtr<Expression> m_case_expression;
|
|
|
|
|
Vector<WhenThenClause> m_when_then_clauses;
|
|
|
|
|
RefPtr<Expression> m_else_expression;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-23 15:29:28 -04:00
|
|
|
class ExistsExpression : public Expression {
|
|
|
|
|
public:
|
|
|
|
|
ExistsExpression(NonnullRefPtr<Select> select_statement, bool invert_expression)
|
|
|
|
|
: m_select_statement(move(select_statement))
|
|
|
|
|
, m_invert_expression(invert_expression)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<Select> const& select_statement() const { return m_select_statement; }
|
2021-04-23 15:29:28 -04:00
|
|
|
bool invert_expression() const { return m_invert_expression; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<Select> m_select_statement;
|
|
|
|
|
bool m_invert_expression;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-20 17:49:26 -04:00
|
|
|
class CollateExpression : public NestedExpression {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
CollateExpression(NonnullRefPtr<Expression> expression, DeprecatedString collation_name)
|
2021-04-20 17:49:26 -04:00
|
|
|
: NestedExpression(move(expression))
|
|
|
|
|
, m_collation_name(move(collation_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& collation_name() const { return m_collation_name; }
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_collation_name;
|
2021-04-20 17:49:26 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class MatchOperator {
|
|
|
|
|
Like,
|
|
|
|
|
Glob,
|
|
|
|
|
Match,
|
|
|
|
|
Regexp,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MatchExpression : public InvertibleNestedDoubleExpression {
|
|
|
|
|
public:
|
|
|
|
|
MatchExpression(MatchOperator type, NonnullRefPtr<Expression> lhs, NonnullRefPtr<Expression> rhs, RefPtr<Expression> escape, bool invert_expression)
|
|
|
|
|
: InvertibleNestedDoubleExpression(move(lhs), move(rhs), invert_expression)
|
|
|
|
|
, m_type(type)
|
|
|
|
|
, m_escape(move(escape))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MatchOperator type() const { return m_type; }
|
2022-04-01 20:58:27 +03:00
|
|
|
RefPtr<Expression> const& escape() const { return m_escape; }
|
2022-02-10 07:46:36 -05:00
|
|
|
virtual ResultOr<Value> evaluate(ExecutionContext&) const override;
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MatchOperator m_type;
|
|
|
|
|
RefPtr<Expression> m_escape;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NullExpression : public InvertibleNestedExpression {
|
|
|
|
|
public:
|
|
|
|
|
NullExpression(NonnullRefPtr<Expression> expression, bool invert_expression)
|
|
|
|
|
: InvertibleNestedExpression(move(expression), invert_expression)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class IsExpression : public InvertibleNestedDoubleExpression {
|
|
|
|
|
public:
|
|
|
|
|
IsExpression(NonnullRefPtr<Expression> lhs, NonnullRefPtr<Expression> rhs, bool invert_expression)
|
|
|
|
|
: InvertibleNestedDoubleExpression(move(lhs), move(rhs), invert_expression)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class BetweenExpression : public InvertibleNestedDoubleExpression {
|
|
|
|
|
public:
|
|
|
|
|
BetweenExpression(NonnullRefPtr<Expression> expression, NonnullRefPtr<Expression> lhs, NonnullRefPtr<Expression> rhs, bool invert_expression)
|
|
|
|
|
: InvertibleNestedDoubleExpression(move(lhs), move(rhs), invert_expression)
|
|
|
|
|
, m_expression(move(expression))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<Expression> const& expression() const { return m_expression; }
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<Expression> m_expression;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-23 14:54:37 -04:00
|
|
|
class InSelectionExpression : public InvertibleNestedExpression {
|
|
|
|
|
public:
|
|
|
|
|
InSelectionExpression(NonnullRefPtr<Expression> expression, NonnullRefPtr<Select> select_statement, bool invert_expression)
|
|
|
|
|
: InvertibleNestedExpression(move(expression), invert_expression)
|
|
|
|
|
, m_select_statement(move(select_statement))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<Select> const& select_statement() const { return m_select_statement; }
|
2021-04-23 14:54:37 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<Select> m_select_statement;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-20 17:49:26 -04:00
|
|
|
class InChainedExpression : public InvertibleNestedExpression {
|
|
|
|
|
public:
|
|
|
|
|
InChainedExpression(NonnullRefPtr<Expression> expression, NonnullRefPtr<ChainedExpression> expression_chain, bool invert_expression)
|
|
|
|
|
: InvertibleNestedExpression(move(expression), invert_expression)
|
|
|
|
|
, m_expression_chain(move(expression_chain))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<ChainedExpression> const& expression_chain() const { return m_expression_chain; }
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<ChainedExpression> m_expression_chain;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class InTableExpression : public InvertibleNestedExpression {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
InTableExpression(NonnullRefPtr<Expression> expression, DeprecatedString schema_name, DeprecatedString table_name, bool invert_expression)
|
2021-04-20 17:49:26 -04:00
|
|
|
: InvertibleNestedExpression(move(expression), invert_expression)
|
|
|
|
|
, m_schema_name(move(schema_name))
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& schema_name() const { return m_schema_name; }
|
|
|
|
|
DeprecatedString const& table_name() const { return m_table_name; }
|
2021-04-20 17:49:26 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_schema_name;
|
|
|
|
|
DeprecatedString m_table_name;
|
2021-04-20 17:49:26 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
|
// Statements
|
|
|
|
|
//==================================================================================================
|
|
|
|
|
|
|
|
|
|
class Statement : public ASTNode {
|
2021-06-27 21:32:22 -04:00
|
|
|
public:
|
2022-12-01 22:20:55 -05:00
|
|
|
ResultOr<ResultSet> execute(AK::NonnullRefPtr<Database> database, Span<Value const> placeholder_values = {}) const;
|
2022-02-09 15:57:57 -05:00
|
|
|
|
2022-02-10 14:43:00 -05:00
|
|
|
virtual ResultOr<ResultSet> execute(ExecutionContext&) const
|
2022-02-09 15:57:57 -05:00
|
|
|
{
|
2022-02-10 14:43:00 -05:00
|
|
|
return Result { SQLCommand::Unknown, SQLErrorCode::NotYetImplemented };
|
2022-02-09 15:57:57 -05:00
|
|
|
}
|
2021-04-20 17:49:26 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ErrorStatement final : public Statement {
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-27 21:32:22 -04:00
|
|
|
class CreateSchema : public Statement {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
CreateSchema(DeprecatedString schema_name, bool is_error_if_schema_exists)
|
2021-06-27 21:32:22 -04:00
|
|
|
: m_schema_name(move(schema_name))
|
|
|
|
|
, m_is_error_if_schema_exists(is_error_if_schema_exists)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& schema_name() const { return m_schema_name; }
|
2021-06-27 21:32:22 -04:00
|
|
|
bool is_error_if_schema_exists() const { return m_is_error_if_schema_exists; }
|
|
|
|
|
|
2022-02-10 14:43:00 -05:00
|
|
|
ResultOr<ResultSet> execute(ExecutionContext&) const override;
|
2021-06-27 21:32:22 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_schema_name;
|
2021-06-27 21:32:22 -04:00
|
|
|
bool m_is_error_if_schema_exists;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-18 17:38:38 -04:00
|
|
|
class CreateTable : public Statement {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
CreateTable(DeprecatedString schema_name, DeprecatedString table_name, RefPtr<Select> select_statement, bool is_temporary, bool is_error_if_table_exists)
|
2021-04-23 13:37:47 -04:00
|
|
|
: m_schema_name(move(schema_name))
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
, m_select_statement(move(select_statement))
|
|
|
|
|
, m_is_temporary(is_temporary)
|
|
|
|
|
, m_is_error_if_table_exists(is_error_if_table_exists)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
CreateTable(DeprecatedString schema_name, DeprecatedString table_name, NonnullRefPtrVector<ColumnDefinition> columns, bool is_temporary, bool is_error_if_table_exists)
|
2021-04-18 17:38:38 -04:00
|
|
|
: m_schema_name(move(schema_name))
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
, m_columns(move(columns))
|
|
|
|
|
, m_is_temporary(is_temporary)
|
|
|
|
|
, m_is_error_if_table_exists(is_error_if_table_exists)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& schema_name() const { return m_schema_name; }
|
|
|
|
|
DeprecatedString const& table_name() const { return m_table_name; }
|
2021-04-23 13:37:47 -04:00
|
|
|
|
|
|
|
|
bool has_selection() const { return !m_select_statement.is_null(); }
|
2022-04-01 20:58:27 +03:00
|
|
|
RefPtr<Select> const& select_statement() const { return m_select_statement; }
|
2021-04-23 13:37:47 -04:00
|
|
|
|
|
|
|
|
bool has_columns() const { return !m_columns.is_empty(); }
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtrVector<ColumnDefinition> const& columns() const { return m_columns; }
|
2021-04-23 13:37:47 -04:00
|
|
|
|
2021-04-18 17:38:38 -04:00
|
|
|
bool is_temporary() const { return m_is_temporary; }
|
|
|
|
|
bool is_error_if_table_exists() const { return m_is_error_if_table_exists; }
|
|
|
|
|
|
2022-02-10 14:43:00 -05:00
|
|
|
ResultOr<ResultSet> execute(ExecutionContext&) const override;
|
2021-06-27 21:32:22 -04:00
|
|
|
|
2021-04-18 17:38:38 -04:00
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_schema_name;
|
|
|
|
|
DeprecatedString m_table_name;
|
2021-04-23 13:37:47 -04:00
|
|
|
RefPtr<Select> m_select_statement;
|
2021-04-18 17:38:38 -04:00
|
|
|
NonnullRefPtrVector<ColumnDefinition> m_columns;
|
|
|
|
|
bool m_is_temporary;
|
|
|
|
|
bool m_is_error_if_table_exists;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-23 22:18:35 -04:00
|
|
|
class AlterTable : public Statement {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& schema_name() const { return m_schema_name; }
|
|
|
|
|
DeprecatedString const& table_name() const { return m_table_name; }
|
2021-04-23 22:18:35 -04:00
|
|
|
|
|
|
|
|
protected:
|
2022-12-04 18:02:33 +00:00
|
|
|
AlterTable(DeprecatedString schema_name, DeprecatedString table_name)
|
2021-04-23 22:18:35 -04:00
|
|
|
: m_schema_name(move(schema_name))
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_schema_name;
|
|
|
|
|
DeprecatedString m_table_name;
|
2021-04-23 22:18:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RenameTable : public AlterTable {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
RenameTable(DeprecatedString schema_name, DeprecatedString table_name, DeprecatedString new_table_name)
|
2021-04-23 22:18:35 -04:00
|
|
|
: AlterTable(move(schema_name), move(table_name))
|
|
|
|
|
, m_new_table_name(move(new_table_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& new_table_name() const { return m_new_table_name; }
|
2021-04-23 22:18:35 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_new_table_name;
|
2021-04-23 22:18:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RenameColumn : public AlterTable {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
RenameColumn(DeprecatedString schema_name, DeprecatedString table_name, DeprecatedString column_name, DeprecatedString new_column_name)
|
2021-04-23 22:18:35 -04:00
|
|
|
: AlterTable(move(schema_name), move(table_name))
|
|
|
|
|
, m_column_name(move(column_name))
|
|
|
|
|
, m_new_column_name(move(new_column_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& column_name() const { return m_column_name; }
|
|
|
|
|
DeprecatedString const& new_column_name() const { return m_new_column_name; }
|
2021-04-23 22:18:35 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_column_name;
|
|
|
|
|
DeprecatedString m_new_column_name;
|
2021-04-23 22:18:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class AddColumn : public AlterTable {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
AddColumn(DeprecatedString schema_name, DeprecatedString table_name, NonnullRefPtr<ColumnDefinition> column)
|
2021-04-23 22:18:35 -04:00
|
|
|
: AlterTable(move(schema_name), move(table_name))
|
|
|
|
|
, m_column(move(column))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<ColumnDefinition> const& column() const { return m_column; }
|
2021-04-23 22:18:35 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<ColumnDefinition> m_column;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DropColumn : public AlterTable {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
DropColumn(DeprecatedString schema_name, DeprecatedString table_name, DeprecatedString column_name)
|
2021-04-23 22:18:35 -04:00
|
|
|
: AlterTable(move(schema_name), move(table_name))
|
|
|
|
|
, m_column_name(move(column_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& column_name() const { return m_column_name; }
|
2021-04-23 22:18:35 -04:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_column_name;
|
2021-04-23 22:18:35 -04:00
|
|
|
};
|
|
|
|
|
|
2021-04-20 10:16:28 -04:00
|
|
|
class DropTable : public Statement {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
DropTable(DeprecatedString schema_name, DeprecatedString table_name, bool is_error_if_table_does_not_exist)
|
2021-04-20 10:16:28 -04:00
|
|
|
: m_schema_name(move(schema_name))
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
, m_is_error_if_table_does_not_exist(is_error_if_table_does_not_exist)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& schema_name() const { return m_schema_name; }
|
|
|
|
|
DeprecatedString const& table_name() const { return m_table_name; }
|
2021-04-20 10:16:28 -04:00
|
|
|
bool is_error_if_table_does_not_exist() const { return m_is_error_if_table_does_not_exist; }
|
|
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_schema_name;
|
|
|
|
|
DeprecatedString m_table_name;
|
2021-04-20 10:16:28 -04:00
|
|
|
bool m_is_error_if_table_does_not_exist;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-23 17:55:23 -04:00
|
|
|
enum class ConflictResolution {
|
|
|
|
|
Abort,
|
|
|
|
|
Fail,
|
|
|
|
|
Ignore,
|
|
|
|
|
Replace,
|
|
|
|
|
Rollback,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Insert : public Statement {
|
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
Insert(RefPtr<CommonTableExpressionList> common_table_expression_list, ConflictResolution conflict_resolution, DeprecatedString schema_name, DeprecatedString table_name, DeprecatedString alias, Vector<DeprecatedString> column_names, NonnullRefPtrVector<ChainedExpression> chained_expressions)
|
2021-04-23 17:55:23 -04:00
|
|
|
: m_common_table_expression_list(move(common_table_expression_list))
|
|
|
|
|
, m_conflict_resolution(conflict_resolution)
|
|
|
|
|
, m_schema_name(move(schema_name))
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
, m_alias(move(alias))
|
|
|
|
|
, m_column_names(move(column_names))
|
|
|
|
|
, m_chained_expressions(move(chained_expressions))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
Insert(RefPtr<CommonTableExpressionList> common_table_expression_list, ConflictResolution conflict_resolution, DeprecatedString schema_name, DeprecatedString table_name, DeprecatedString alias, Vector<DeprecatedString> column_names, RefPtr<Select> select_statement)
|
2021-04-23 17:55:23 -04:00
|
|
|
: m_common_table_expression_list(move(common_table_expression_list))
|
|
|
|
|
, m_conflict_resolution(conflict_resolution)
|
|
|
|
|
, m_schema_name(move(schema_name))
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
, m_alias(move(alias))
|
|
|
|
|
, m_column_names(move(column_names))
|
|
|
|
|
, m_select_statement(move(select_statement))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
Insert(RefPtr<CommonTableExpressionList> common_table_expression_list, ConflictResolution conflict_resolution, DeprecatedString schema_name, DeprecatedString table_name, DeprecatedString alias, Vector<DeprecatedString> column_names)
|
2021-04-23 17:55:23 -04:00
|
|
|
: m_common_table_expression_list(move(common_table_expression_list))
|
|
|
|
|
, m_conflict_resolution(conflict_resolution)
|
|
|
|
|
, m_schema_name(move(schema_name))
|
|
|
|
|
, m_table_name(move(table_name))
|
|
|
|
|
, m_alias(move(alias))
|
|
|
|
|
, m_column_names(move(column_names))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
RefPtr<CommonTableExpressionList> const& common_table_expression_list() const { return m_common_table_expression_list; }
|
2021-04-23 17:55:23 -04:00
|
|
|
ConflictResolution conflict_resolution() const { return m_conflict_resolution; }
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& schema_name() const { return m_schema_name; }
|
|
|
|
|
DeprecatedString const& table_name() const { return m_table_name; }
|
|
|
|
|
DeprecatedString const& alias() const { return m_alias; }
|
|
|
|
|
Vector<DeprecatedString> const& column_names() const { return m_column_names; }
|
2021-04-23 17:55:23 -04:00
|
|
|
|
|
|
|
|
bool default_values() const { return !has_expressions() && !has_selection(); };
|
|
|
|
|
|
|
|
|
|
bool has_expressions() const { return !m_chained_expressions.is_empty(); }
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtrVector<ChainedExpression> const& chained_expressions() const { return m_chained_expressions; }
|
2021-04-23 17:55:23 -04:00
|
|
|
|
|
|
|
|
bool has_selection() const { return !m_select_statement.is_null(); }
|
2022-04-01 20:58:27 +03:00
|
|
|
RefPtr<Select> const& select_statement() const { return m_select_statement; }
|
2021-04-23 17:55:23 -04:00
|
|
|
|
2022-02-10 14:43:00 -05:00
|
|
|
virtual ResultOr<ResultSet> execute(ExecutionContext&) const override;
|
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.
2021-07-19 19:48:46 -04:00
|
|
|
|
2021-04-23 17:55:23 -04:00
|
|
|
private:
|
|
|
|
|
RefPtr<CommonTableExpressionList> m_common_table_expression_list;
|
|
|
|
|
ConflictResolution m_conflict_resolution;
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_schema_name;
|
|
|
|
|
DeprecatedString m_table_name;
|
|
|
|
|
DeprecatedString m_alias;
|
|
|
|
|
Vector<DeprecatedString> m_column_names;
|
2021-04-23 17:55:23 -04:00
|
|
|
NonnullRefPtrVector<ChainedExpression> m_chained_expressions;
|
|
|
|
|
RefPtr<Select> m_select_statement;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-23 21:40:19 -04:00
|
|
|
class Update : public Statement {
|
|
|
|
|
public:
|
|
|
|
|
struct UpdateColumns {
|
2022-12-04 18:02:33 +00:00
|
|
|
Vector<DeprecatedString> column_names;
|
2021-04-23 21:40:19 -04:00
|
|
|
NonnullRefPtr<Expression> expression;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Update(RefPtr<CommonTableExpressionList> common_table_expression_list, ConflictResolution conflict_resolution, NonnullRefPtr<QualifiedTableName> qualified_table_name, Vector<UpdateColumns> update_columns, NonnullRefPtrVector<TableOrSubquery> table_or_subquery_list, RefPtr<Expression> where_clause, RefPtr<ReturningClause> returning_clause)
|
|
|
|
|
: m_common_table_expression_list(move(common_table_expression_list))
|
|
|
|
|
, m_conflict_resolution(conflict_resolution)
|
|
|
|
|
, m_qualified_table_name(move(qualified_table_name))
|
|
|
|
|
, m_update_columns(move(update_columns))
|
|
|
|
|
, m_table_or_subquery_list(move(table_or_subquery_list))
|
|
|
|
|
, m_where_clause(move(where_clause))
|
|
|
|
|
, m_returning_clause(move(returning_clause))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
RefPtr<CommonTableExpressionList> const& common_table_expression_list() const { return m_common_table_expression_list; }
|
2021-04-23 21:40:19 -04:00
|
|
|
ConflictResolution conflict_resolution() const { return m_conflict_resolution; }
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtr<QualifiedTableName> const& qualified_table_name() const { return m_qualified_table_name; }
|
|
|
|
|
Vector<UpdateColumns> const& update_columns() const { return m_update_columns; }
|
|
|
|
|
NonnullRefPtrVector<TableOrSubquery> const& table_or_subquery_list() const { return m_table_or_subquery_list; }
|
|
|
|
|
RefPtr<Expression> const& where_clause() const { return m_where_clause; }
|
|
|
|
|
RefPtr<ReturningClause> const& returning_clause() const { return m_returning_clause; }
|
2021-04-23 21:40:19 -04:00
|
|
|
|
2022-12-05 07:55:21 -05:00
|
|
|
virtual ResultOr<ResultSet> execute(ExecutionContext&) const override;
|
|
|
|
|
|
2021-04-23 21:40:19 -04:00
|
|
|
private:
|
|
|
|
|
RefPtr<CommonTableExpressionList> m_common_table_expression_list;
|
|
|
|
|
ConflictResolution m_conflict_resolution;
|
|
|
|
|
NonnullRefPtr<QualifiedTableName> m_qualified_table_name;
|
|
|
|
|
Vector<UpdateColumns> m_update_columns;
|
|
|
|
|
NonnullRefPtrVector<TableOrSubquery> m_table_or_subquery_list;
|
|
|
|
|
RefPtr<Expression> m_where_clause;
|
|
|
|
|
RefPtr<ReturningClause> m_returning_clause;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-21 14:13:05 -04:00
|
|
|
class Delete : public Statement {
|
|
|
|
|
public:
|
2021-04-21 16:56:19 -04:00
|
|
|
Delete(RefPtr<CommonTableExpressionList> common_table_expression_list, NonnullRefPtr<QualifiedTableName> qualified_table_name, RefPtr<Expression> where_clause, RefPtr<ReturningClause> returning_clause)
|
|
|
|
|
: m_common_table_expression_list(move(common_table_expression_list))
|
2021-04-21 14:13:05 -04:00
|
|
|
, m_qualified_table_name(move(qualified_table_name))
|
|
|
|
|
, m_where_clause(move(where_clause))
|
|
|
|
|
, m_returning_clause(move(returning_clause))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
RefPtr<CommonTableExpressionList> const& common_table_expression_list() const { return m_common_table_expression_list; }
|
|
|
|
|
NonnullRefPtr<QualifiedTableName> const& qualified_table_name() const { return m_qualified_table_name; }
|
|
|
|
|
RefPtr<Expression> const& where_clause() const { return m_where_clause; }
|
|
|
|
|
RefPtr<ReturningClause> const& returning_clause() const { return m_returning_clause; }
|
2021-04-21 14:13:05 -04:00
|
|
|
|
2022-11-28 07:49:03 -05:00
|
|
|
virtual ResultOr<ResultSet> execute(ExecutionContext&) const override;
|
|
|
|
|
|
2021-04-21 14:13:05 -04:00
|
|
|
private:
|
2021-04-21 16:56:19 -04:00
|
|
|
RefPtr<CommonTableExpressionList> m_common_table_expression_list;
|
2021-04-21 14:13:05 -04:00
|
|
|
NonnullRefPtr<QualifiedTableName> m_qualified_table_name;
|
|
|
|
|
RefPtr<Expression> m_where_clause;
|
|
|
|
|
RefPtr<ReturningClause> m_returning_clause;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-22 10:11:17 -04:00
|
|
|
class Select : public Statement {
|
|
|
|
|
public:
|
|
|
|
|
Select(RefPtr<CommonTableExpressionList> common_table_expression_list, bool select_all, NonnullRefPtrVector<ResultColumn> result_column_list, NonnullRefPtrVector<TableOrSubquery> table_or_subquery_list, RefPtr<Expression> where_clause, RefPtr<GroupByClause> group_by_clause, NonnullRefPtrVector<OrderingTerm> ordering_term_list, RefPtr<LimitClause> limit_clause)
|
|
|
|
|
: m_common_table_expression_list(move(common_table_expression_list))
|
|
|
|
|
, m_select_all(move(select_all))
|
|
|
|
|
, m_result_column_list(move(result_column_list))
|
|
|
|
|
, m_table_or_subquery_list(move(table_or_subquery_list))
|
|
|
|
|
, m_where_clause(move(where_clause))
|
|
|
|
|
, m_group_by_clause(move(group_by_clause))
|
|
|
|
|
, m_ordering_term_list(move(ordering_term_list))
|
|
|
|
|
, m_limit_clause(move(limit_clause))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
RefPtr<CommonTableExpressionList> const& common_table_expression_list() const { return m_common_table_expression_list; }
|
2021-04-22 10:11:17 -04:00
|
|
|
bool select_all() const { return m_select_all; }
|
2022-04-01 20:58:27 +03:00
|
|
|
NonnullRefPtrVector<ResultColumn> const& result_column_list() const { return m_result_column_list; }
|
|
|
|
|
NonnullRefPtrVector<TableOrSubquery> const& table_or_subquery_list() const { return m_table_or_subquery_list; }
|
|
|
|
|
RefPtr<Expression> const& where_clause() const { return m_where_clause; }
|
|
|
|
|
RefPtr<GroupByClause> const& group_by_clause() const { return m_group_by_clause; }
|
|
|
|
|
NonnullRefPtrVector<OrderingTerm> const& ordering_term_list() const { return m_ordering_term_list; }
|
|
|
|
|
RefPtr<LimitClause> const& limit_clause() const { return m_limit_clause; }
|
2022-02-10 14:43:00 -05:00
|
|
|
ResultOr<ResultSet> execute(ExecutionContext&) const override;
|
2021-04-22 10:11:17 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
RefPtr<CommonTableExpressionList> m_common_table_expression_list;
|
|
|
|
|
bool m_select_all;
|
|
|
|
|
NonnullRefPtrVector<ResultColumn> m_result_column_list;
|
|
|
|
|
NonnullRefPtrVector<TableOrSubquery> m_table_or_subquery_list;
|
|
|
|
|
RefPtr<Expression> m_where_clause;
|
|
|
|
|
RefPtr<GroupByClause> m_group_by_clause;
|
|
|
|
|
NonnullRefPtrVector<OrderingTerm> m_ordering_term_list;
|
|
|
|
|
RefPtr<LimitClause> m_limit_clause;
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-06 15:30:38 +02:00
|
|
|
class DescribeTable : public Statement {
|
|
|
|
|
public:
|
|
|
|
|
DescribeTable(NonnullRefPtr<QualifiedTableName> qualified_table_name)
|
|
|
|
|
: m_qualified_table_name(move(qualified_table_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NonnullRefPtr<QualifiedTableName> qualified_table_name() const { return m_qualified_table_name; }
|
2022-02-10 14:43:00 -05:00
|
|
|
ResultOr<ResultSet> execute(ExecutionContext&) const override;
|
2021-12-06 15:30:38 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NonnullRefPtr<QualifiedTableName> m_qualified_table_name;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-18 17:38:38 -04:00
|
|
|
}
|