1#include "duckdb/execution/expression_executor.hpp"
2#include "duckdb/main/client_context.hpp"
3#include "duckdb/parser/statement/execute_statement.hpp"
4#include "duckdb/planner/binder.hpp"
5#include "duckdb/planner/operator/logical_execute.hpp"
6#include "duckdb/planner/expression_binder/constant_binder.hpp"
7#include "duckdb/catalog/catalog_entry/prepared_statement_catalog_entry.hpp"
8
9using namespace duckdb;
10using namespace std;
11
12BoundStatement Binder::Bind(ExecuteStatement &stmt) {
13 BoundStatement result;
14
15 // bind the prepared statement
16 auto entry =
17 (PreparedStatementCatalogEntry *)context.prepared_statements->GetEntry(context.ActiveTransaction(), stmt.name);
18 if (!entry || entry->deleted) {
19 throw BinderException("Could not find prepared statement with that name");
20 }
21 auto prepared = entry->prepared.get();
22 this->read_only = prepared->read_only;
23 this->requires_valid_transaction = prepared->requires_valid_transaction;
24
25 vector<Value> bind_values;
26 for (idx_t i = 0; i < stmt.values.size(); i++) {
27 ConstantBinder binder(*this, context, "EXECUTE statement");
28 binder.target_type = prepared->GetType(i + 1);
29 auto bound_expr = binder.Bind(stmt.values[i]);
30
31 Value value = ExpressionExecutor::EvaluateScalar(*bound_expr);
32 bind_values.push_back(move(value));
33 }
34 prepared->Bind(move(bind_values));
35
36 result.plan = make_unique<LogicalExecute>(prepared);
37 result.names = prepared->names;
38 result.types = prepared->sql_types;
39
40 return result;
41}
42