1#include "duckdb/main/relation/delete_relation.hpp"
2#include "duckdb/parser/statement/delete_statement.hpp"
3#include "duckdb/planner/binder.hpp"
4#include "duckdb/main/client_context.hpp"
5#include "duckdb/parser/tableref/basetableref.hpp"
6
7namespace duckdb {
8
9DeleteRelation::DeleteRelation(ClientContextWrapper &context, unique_ptr<ParsedExpression> condition_p,
10 string schema_name_p, string table_name_p)
11 : Relation(context, RelationType::DELETE_RELATION), condition(std::move(condition_p)),
12 schema_name(std::move(schema_name_p)), table_name(std::move(table_name_p)) {
13 context.GetContext()->TryBindRelation(relation&: *this, result_columns&: this->columns);
14}
15
16BoundStatement DeleteRelation::Bind(Binder &binder) {
17 auto basetable = make_uniq<BaseTableRef>();
18 basetable->schema_name = schema_name;
19 basetable->table_name = table_name;
20
21 DeleteStatement stmt;
22 stmt.condition = condition ? condition->Copy() : nullptr;
23 stmt.table = std::move(basetable);
24 return binder.Bind(statement&: stmt.Cast<SQLStatement>());
25}
26
27const vector<ColumnDefinition> &DeleteRelation::Columns() {
28 return columns;
29}
30
31string DeleteRelation::ToString(idx_t depth) {
32 string str = RenderWhitespace(depth) + "DELETE FROM " + table_name;
33 if (condition) {
34 str += " WHERE " + condition->ToString();
35 }
36 return str;
37}
38
39} // namespace duckdb
40