| 1 | #include "duckdb/main/prepared_statement_data.hpp" |
|---|---|
| 2 | #include "duckdb/execution/physical_operator.hpp" |
| 3 | |
| 4 | using namespace duckdb; |
| 5 | using namespace std; |
| 6 | |
| 7 | PreparedStatementData::PreparedStatementData(StatementType type) |
| 8 | : statement_type(type), read_only(true), requires_valid_transaction(true) { |
| 9 | } |
| 10 | |
| 11 | PreparedStatementData::~PreparedStatementData() { |
| 12 | } |
| 13 | |
| 14 | void PreparedStatementData::Bind(vector<Value> values) { |
| 15 | // set parameters |
| 16 | if (values.size() != value_map.size()) { |
| 17 | throw BinderException("Parameter/argument count mismatch for prepared statement"); |
| 18 | } |
| 19 | // bind the values |
| 20 | for (idx_t i = 0; i < values.size(); i++) { |
| 21 | auto it = value_map.find(i + 1); |
| 22 | if (it == value_map.end()) { |
| 23 | throw BinderException("Could not find parameter with index %llu", i + 1); |
| 24 | } |
| 25 | if (values[i].type != GetInternalType(it->second.target_type)) { |
| 26 | throw BinderException( |
| 27 | "Type mismatch for binding parameter with index %llu, expected type %s but got type %s", i + 1, |
| 28 | TypeIdToString(values[i].type).c_str(), |
| 29 | TypeIdToString(GetInternalType(it->second.target_type)).c_str()); |
| 30 | } |
| 31 | auto &target = it->second; |
| 32 | *target.value = values[i]; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | SQLType PreparedStatementData::GetType(idx_t param_idx) { |
| 37 | auto it = value_map.find(param_idx); |
| 38 | if (it == value_map.end()) { |
| 39 | throw BinderException("Could not find parameter with index %llu", param_idx); |
| 40 | } |
| 41 | return it->second.target_type; |
| 42 | } |
| 43 |