1#include "duckdb/parser/statement/drop_statement.hpp"
2#include "duckdb/planner/binder.hpp"
3#include "duckdb/planner/bound_tableref.hpp"
4#include "duckdb/planner/operator/logical_simple.hpp"
5#include "duckdb/catalog/catalog.hpp"
6#include "duckdb/catalog/standard_entry.hpp"
7#include "duckdb/catalog/catalog_entry/schema_catalog_entry.hpp"
8#include "duckdb/parser/parsed_data/drop_info.hpp"
9#include "duckdb/main/config.hpp"
10#include "duckdb/storage/storage_extension.hpp"
11
12namespace duckdb {
13
14BoundStatement Binder::Bind(DropStatement &stmt) {
15 BoundStatement result;
16
17 switch (stmt.info->type) {
18 case CatalogType::PREPARED_STATEMENT:
19 // dropping prepared statements is always possible
20 // it also does not require a valid transaction
21 properties.requires_valid_transaction = false;
22 break;
23 case CatalogType::SCHEMA_ENTRY: {
24 // dropping a schema is never read-only because there are no temporary schemas
25 auto &catalog = Catalog::GetCatalog(context, catalog_name: stmt.info->catalog);
26 properties.modified_databases.insert(x: catalog.GetName());
27 break;
28 }
29 case CatalogType::VIEW_ENTRY:
30 case CatalogType::SEQUENCE_ENTRY:
31 case CatalogType::MACRO_ENTRY:
32 case CatalogType::TABLE_MACRO_ENTRY:
33 case CatalogType::INDEX_ENTRY:
34 case CatalogType::TABLE_ENTRY:
35 case CatalogType::TYPE_ENTRY: {
36 BindSchemaOrCatalog(catalog&: stmt.info->catalog, schema&: stmt.info->schema);
37 auto entry = Catalog::GetEntry(context, type: stmt.info->type, catalog: stmt.info->catalog, schema: stmt.info->schema, name: stmt.info->name,
38 if_not_found: OnEntryNotFound::RETURN_NULL);
39 if (!entry) {
40 break;
41 }
42 stmt.info->catalog = entry->ParentCatalog().GetName();
43 if (!entry->temporary) {
44 // we can only drop temporary tables in read-only mode
45 properties.modified_databases.insert(x: stmt.info->catalog);
46 }
47 stmt.info->schema = entry->ParentSchema().name;
48 break;
49 }
50 default:
51 throw BinderException("Unknown catalog type for drop statement!");
52 }
53 result.plan = make_uniq<LogicalSimple>(args: LogicalOperatorType::LOGICAL_DROP, args: std::move(stmt.info));
54 result.names = {"Success"};
55 result.types = {LogicalType::BOOLEAN};
56 properties.allow_stream_result = false;
57 properties.return_type = StatementReturnType::NOTHING;
58 return result;
59}
60
61} // namespace duckdb
62