1#include "duckdb/parser/transformer.hpp"
2
3#include "duckdb/parser/expression/list.hpp"
4#include "duckdb/parser/statement/list.hpp"
5#include "duckdb/parser/tableref/emptytableref.hpp"
6
7using namespace duckdb;
8using namespace std;
9
10bool Transformer::TransformParseTree(PGList *tree, vector<unique_ptr<SQLStatement>> &statements) {
11 for (auto entry = tree->head; entry != nullptr; entry = entry->next) {
12 auto stmt = TransformStatement((PGNode *)entry->data.ptr_value);
13 if (!stmt) {
14 statements.clear();
15 return false;
16 }
17 statements.push_back(move(stmt));
18 }
19 return true;
20}
21
22unique_ptr<SQLStatement> Transformer::TransformStatement(PGNode *stmt) {
23 switch (stmt->type) {
24 case T_PGRawStmt: {
25 auto raw_stmt = (PGRawStmt *)stmt;
26 auto result = TransformStatement(raw_stmt->stmt);
27 if (result) {
28 result->stmt_location = raw_stmt->stmt_location;
29 result->stmt_length = raw_stmt->stmt_len;
30 }
31 return result;
32 }
33 case T_PGSelectStmt:
34 return TransformSelect(stmt);
35 case T_PGCreateStmt:
36 return TransformCreateTable(stmt);
37 case T_PGCreateSchemaStmt:
38 return TransformCreateSchema(stmt);
39 case T_PGViewStmt:
40 return TransformCreateView(stmt);
41 case T_PGCreateSeqStmt:
42 return TransformCreateSequence(stmt);
43 case T_PGDropStmt:
44 return TransformDrop(stmt);
45 case T_PGInsertStmt:
46 return TransformInsert(stmt);
47 case T_PGCopyStmt:
48 return TransformCopy(stmt);
49 case T_PGTransactionStmt:
50 return TransformTransaction(stmt);
51 case T_PGDeleteStmt:
52 return TransformDelete(stmt);
53 case T_PGUpdateStmt:
54 return TransformUpdate(stmt);
55 case T_PGIndexStmt:
56 return TransformCreateIndex(stmt);
57 case T_PGAlterTableStmt:
58 return TransformAlter(stmt);
59 case T_PGRenameStmt:
60 return TransformRename(stmt);
61 case T_PGPrepareStmt:
62 return TransformPrepare(stmt);
63 case T_PGExecuteStmt:
64 return TransformExecute(stmt);
65 case T_PGDeallocateStmt:
66 return TransformDeallocate(stmt);
67 case T_PGCreateTableAsStmt:
68 return TransformCreateTableAs(stmt);
69 case T_PGPragmaStmt:
70 return TransformPragma(stmt);
71 case T_PGExplainStmt:
72 return TransformExplain(stmt);
73 case T_PGVacuumStmt:
74 return TransformVacuum(stmt);
75 case T_PGVariableShowStmt:
76 return TransformShow(stmt);
77 default:
78 throw NotImplementedException(NodetypeToString(stmt->type));
79 }
80 return nullptr;
81}
82