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
6namespace duckdb {
7
8unique_ptr<PrepareStatement> Transformer::TransformPrepare(duckdb_libpgquery::PGPrepareStmt &stmt) {
9 if (stmt.argtypes && stmt.argtypes->length > 0) {
10 throw NotImplementedException("Prepared statement argument types are not supported, use CAST");
11 }
12
13 auto result = make_uniq<PrepareStatement>();
14 result->name = string(stmt.name);
15 result->statement = TransformStatement(stmt&: *stmt.query);
16 if (!result->statement->named_param_map.empty()) {
17 throw NotImplementedException("Named parameters are not supported in this client yet");
18 }
19 SetParamCount(0);
20
21 return result;
22}
23
24unique_ptr<ExecuteStatement> Transformer::TransformExecute(duckdb_libpgquery::PGExecuteStmt &stmt) {
25 auto result = make_uniq<ExecuteStatement>();
26 result->name = string(stmt.name);
27
28 if (stmt.params) {
29 TransformExpressionList(list&: *stmt.params, result&: result->values);
30 }
31 for (auto &expr : result->values) {
32 if (!expr->IsScalar()) {
33 throw Exception("Only scalar parameters or NULL supported for EXECUTE");
34 }
35 }
36 return result;
37}
38
39unique_ptr<DropStatement> Transformer::TransformDeallocate(duckdb_libpgquery::PGDeallocateStmt &stmt) {
40 if (!stmt.name) {
41 throw ParserException("DEALLOCATE requires a name");
42 }
43
44 auto result = make_uniq<DropStatement>();
45 result->info->type = CatalogType::PREPARED_STATEMENT;
46 result->info->name = string(stmt.name);
47 return result;
48}
49
50} // namespace duckdb
51