1#include "duckdb/parser/statement/drop_statement.hpp"
2#include "duckdb/parser/transformer.hpp"
3
4using namespace duckdb;
5using namespace std;
6
7unique_ptr<SQLStatement> Transformer::TransformDrop(PGNode *node) {
8 auto stmt = (PGDropStmt *)(node);
9 auto result = make_unique<DropStatement>();
10 auto &info = *result->info.get();
11 assert(stmt);
12 if (stmt->objects->length != 1) {
13 throw NotImplementedException("Can only drop one object at a time");
14 }
15 switch (stmt->removeType) {
16 case PG_OBJECT_TABLE:
17 info.type = CatalogType::TABLE;
18 break;
19 case PG_OBJECT_SCHEMA:
20 info.type = CatalogType::SCHEMA;
21 break;
22 case PG_OBJECT_INDEX:
23 info.type = CatalogType::INDEX;
24 break;
25 case PG_OBJECT_VIEW:
26 info.type = CatalogType::VIEW;
27 break;
28 case PG_OBJECT_SEQUENCE:
29 info.type = CatalogType::SEQUENCE;
30 break;
31 default:
32 throw NotImplementedException("Cannot drop this type yet");
33 }
34
35 switch (stmt->removeType) {
36 case PG_OBJECT_SCHEMA:
37 assert(stmt->objects && stmt->objects->length == 1);
38 info.name = ((PGValue *)stmt->objects->head->data.ptr_value)->val.str;
39 break;
40 default: {
41 auto view_list = (PGList *)stmt->objects->head->data.ptr_value;
42 if (view_list->length == 2) {
43 info.schema = ((PGValue *)view_list->head->data.ptr_value)->val.str;
44 info.name = ((PGValue *)view_list->head->next->data.ptr_value)->val.str;
45 } else {
46 info.name = ((PGValue *)view_list->head->data.ptr_value)->val.str;
47 }
48 break;
49 }
50 }
51 info.cascade = stmt->behavior == PGDropBehavior::PG_DROP_CASCADE;
52 info.if_exists = stmt->missing_ok;
53 return move(result);
54}
55