1#include "duckdb/parser/statement/drop_statement.hpp"
2#include "duckdb/parser/statement/execute_statement.hpp"
3#include "duckdb/parser/statement/prepare_statement.hpp"
4#include "duckdb/parser/transformer.hpp"
5
6using namespace duckdb;
7using namespace std;
8
9unique_ptr<PrepareStatement> Transformer::TransformPrepare(PGNode *node) {
10 auto stmt = reinterpret_cast<PGPrepareStmt *>(node);
11 assert(stmt);
12
13 if (stmt->argtypes && stmt->argtypes->length > 0) {
14 throw NotImplementedException("Prepared statement argument types are not supported, use CAST");
15 }
16
17 auto result = make_unique<PrepareStatement>();
18 result->name = string(stmt->name);
19 result->statement = TransformStatement(stmt->query);
20 SetParamCount(0);
21
22 return result;
23}
24
25unique_ptr<ExecuteStatement> Transformer::TransformExecute(PGNode *node) {
26 auto stmt = reinterpret_cast<PGExecuteStmt *>(node);
27 assert(stmt);
28
29 auto result = make_unique<ExecuteStatement>();
30 result->name = string(stmt->name);
31
32 TransformExpressionList(stmt->params, result->values);
33 for (auto &expr : result->values) {
34 if (!expr->IsScalar()) {
35 throw Exception("Only scalar parameters or NULL supported for EXECUTE");
36 }
37 }
38 return result;
39}
40
41unique_ptr<DropStatement> Transformer::TransformDeallocate(PGNode *node) {
42 auto stmt = reinterpret_cast<PGDeallocateStmt *>(node);
43 assert(stmt);
44
45 auto result = make_unique<DropStatement>();
46 result->info->type = CatalogType::PREPARED_STATEMENT;
47 result->info->name = string(stmt->name);
48 return result;
49}
50