| 1 | #include "duckdb/main/relation/create_view_relation.hpp" |
| 2 | #include "duckdb/parser/statement/create_statement.hpp" |
| 3 | #include "duckdb/parser/parsed_data/create_view_info.hpp" |
| 4 | #include "duckdb/planner/binder.hpp" |
| 5 | |
| 6 | namespace duckdb { |
| 7 | |
| 8 | CreateViewRelation::CreateViewRelation(shared_ptr<Relation> child_p, string view_name_p, bool replace_p, |
| 9 | bool temporary_p) |
| 10 | : Relation(child_p->context, RelationType::CREATE_VIEW_RELATION), child(std::move(child_p)), |
| 11 | view_name(std::move(view_name_p)), replace(replace_p), temporary(temporary_p) { |
| 12 | context.GetContext()->TryBindRelation(relation&: *this, result_columns&: this->columns); |
| 13 | } |
| 14 | |
| 15 | CreateViewRelation::CreateViewRelation(shared_ptr<Relation> child_p, string schema_name_p, string view_name_p, |
| 16 | bool replace_p, bool temporary_p) |
| 17 | : Relation(child_p->context, RelationType::CREATE_VIEW_RELATION), child(std::move(child_p)), |
| 18 | schema_name(std::move(schema_name_p)), view_name(std::move(view_name_p)), replace(replace_p), |
| 19 | temporary(temporary_p) { |
| 20 | context.GetContext()->TryBindRelation(relation&: *this, result_columns&: this->columns); |
| 21 | } |
| 22 | |
| 23 | BoundStatement CreateViewRelation::Bind(Binder &binder) { |
| 24 | auto select = make_uniq<SelectStatement>(); |
| 25 | select->node = child->GetQueryNode(); |
| 26 | |
| 27 | CreateStatement stmt; |
| 28 | auto info = make_uniq<CreateViewInfo>(); |
| 29 | info->query = std::move(select); |
| 30 | info->view_name = view_name; |
| 31 | info->temporary = temporary; |
| 32 | info->schema = schema_name; |
| 33 | info->on_conflict = replace ? OnCreateConflict::REPLACE_ON_CONFLICT : OnCreateConflict::ERROR_ON_CONFLICT; |
| 34 | stmt.info = std::move(info); |
| 35 | return binder.Bind(statement&: stmt.Cast<SQLStatement>()); |
| 36 | } |
| 37 | |
| 38 | const vector<ColumnDefinition> &CreateViewRelation::Columns() { |
| 39 | return columns; |
| 40 | } |
| 41 | |
| 42 | string CreateViewRelation::ToString(idx_t depth) { |
| 43 | string str = RenderWhitespace(depth) + "Create View\n" ; |
| 44 | return str + child->ToString(depth: depth + 1); |
| 45 | } |
| 46 | |
| 47 | } // namespace duckdb |
| 48 | |