| 185 | } |
| 186 | |
| 187 | lbug_state lbug_connection_execute(lbug_connection* connection, |
| 188 | lbug_prepared_statement* prepared_statement, lbug_query_result* out_query_result) { |
| 189 | if (connection == nullptr || connection->_connection == nullptr || |
| 190 | prepared_statement == nullptr || prepared_statement->_prepared_statement == nullptr || |
| 191 | prepared_statement->_bound_values == nullptr) { |
| 192 | return LbugError; |
| 193 | } |
| 194 | try { |
| 195 | clearLastCAPIErrorMessage(); |
| 196 | auto prepared_statement_ptr = |
| 197 | static_cast<PreparedStatement*>(prepared_statement->_prepared_statement); |
| 198 | auto bound_values = static_cast<std::unordered_map<std::string, std::unique_ptr<Value>>*>( |
| 199 | prepared_statement->_bound_values); |
| 200 | |
| 201 | // Must copy the parameters for safety, and so that the parameters in the prepared statement |
| 202 | // stay the same. |
| 203 | std::unordered_map<std::string, std::unique_ptr<Value>> copied_bound_values; |
| 204 | for (auto& [name, value] : *bound_values) { |
| 205 | copied_bound_values.emplace(name, value->copy()); |
| 206 | } |
| 207 | |
| 208 | auto query_result = |
| 209 | static_cast<Connection*>(connection->_connection) |
| 210 | ->executeWithParams(prepared_statement_ptr, std::move(copied_bound_values)) |
| 211 | .release(); |
| 212 | if (query_result == nullptr) { |
| 213 | return LbugError; |
| 214 | } |
| 215 | out_query_result->_query_result = query_result; |
| 216 | out_query_result->_is_owned_by_cpp = false; |
| 217 | if (!query_result->isSuccess()) { |
| 218 | return LbugError; |
| 219 | } |
| 220 | return LbugSuccess; |
| 221 | } catch (Exception& e) { |
| 222 | setLastCAPIErrorMessage(e.what()); |
| 223 | return LbugError; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | lbug_state lbug_connection_create_arrow_table(lbug_connection* connection, const char* table_name, |
| 228 | ArrowSchema* schema, ArrowArray* arrays, uint64_t num_arrays, |