1#include "duckdb/parser/statement/drop_statement.hpp"
2#include "duckdb/planner/binder.hpp"
3#include "duckdb/planner/operator/logical_simple.hpp"
4#include "duckdb/catalog/catalog.hpp"
5#include "duckdb/catalog/standard_entry.hpp"
6#include "duckdb/catalog/catalog_entry/schema_catalog_entry.hpp"
7
8using namespace duckdb;
9using namespace std;
10
11BoundStatement Binder::Bind(DropStatement &stmt) {
12 BoundStatement result;
13
14 switch (stmt.info->type) {
15 case CatalogType::PREPARED_STATEMENT:
16 // dropping prepared statements is always possible
17 // it also does not require a valid transaction
18 this->requires_valid_transaction = false;
19 break;
20 case CatalogType::SCHEMA:
21 // dropping a schema is never read-only because there are no temporary schemas
22 this->read_only = false;
23 break;
24 case CatalogType::VIEW:
25 case CatalogType::SEQUENCE:
26 case CatalogType::INDEX:
27 case CatalogType::TABLE: {
28 auto entry = (StandardEntry *)Catalog::GetCatalog(context).GetEntry(context, stmt.info->type, stmt.info->schema,
29 stmt.info->name, true);
30 if (!entry) {
31 break;
32 }
33 if (!entry->temporary) {
34 // we can only drop temporary tables in read-only mode
35 this->read_only = false;
36 }
37 stmt.info->schema = entry->schema->name;
38 break;
39 }
40 default:
41 throw BinderException("Unknown catalog type for drop statement!");
42 }
43 result.plan = make_unique<LogicalSimple>(LogicalOperatorType::DROP, move(stmt.info));
44 result.names = {"Success"};
45 result.types = {SQLType::BOOLEAN};
46 return result;
47}
48