1#include "duckdb/execution/operator/schema/physical_drop.hpp"
2#include "duckdb/main/client_data.hpp"
3#include "duckdb/main/database_manager.hpp"
4#include "duckdb/main/database.hpp"
5#include "duckdb/main/client_context.hpp"
6#include "duckdb/catalog/catalog_search_path.hpp"
7#include "duckdb/main/settings.hpp"
8
9namespace duckdb {
10
11//===--------------------------------------------------------------------===//
12// Source
13//===--------------------------------------------------------------------===//
14SourceResultType PhysicalDrop::GetData(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const {
15 switch (info->type) {
16 case CatalogType::PREPARED_STATEMENT: {
17 // DEALLOCATE silently ignores errors
18 auto &statements = ClientData::Get(context&: context.client).prepared_statements;
19 if (statements.find(x: info->name) != statements.end()) {
20 statements.erase(x: info->name);
21 }
22 break;
23 }
24 case CatalogType::SCHEMA_ENTRY: {
25 auto &catalog = Catalog::GetCatalog(context&: context.client, catalog_name: info->catalog);
26 catalog.DropEntry(context&: context.client, info&: *info);
27 auto qualified_name = QualifiedName::Parse(input: info->name);
28
29 // Check if the dropped schema was set as the current schema
30 auto &client_data = ClientData::Get(context&: context.client);
31 auto &default_entry = client_data.catalog_search_path->GetDefault();
32 auto &current_catalog = default_entry.catalog;
33 auto &current_schema = default_entry.schema;
34 D_ASSERT(info->name != DEFAULT_SCHEMA);
35
36 if (info->catalog == current_catalog && current_schema == info->name) {
37 // Reset the schema to default
38 SchemaSetting::SetLocal(context&: context.client, DEFAULT_SCHEMA);
39 }
40 break;
41 }
42 default: {
43 auto &catalog = Catalog::GetCatalog(context&: context.client, catalog_name: info->catalog);
44 catalog.DropEntry(context&: context.client, info&: *info);
45 break;
46 }
47 }
48
49 return SourceResultType::FINISHED;
50}
51
52} // namespace duckdb
53