MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / lbug_connection_execute

Function lbug_connection_execute

src/c_api/connection.cpp:187–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187lbug_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
227lbug_state lbug_connection_create_arrow_table(lbug_connection* connection, const char* table_name,
228 ArrowSchema* schema, ArrowArray* arrays, uint64_t num_arrays,

Callers 3

TEST_FFunction · 0.85
TEST_FFunction · 0.85
TEST_FFunction · 0.85

Calls 7

setLastCAPIErrorMessageFunction · 0.85
releaseMethod · 0.80
whatMethod · 0.80
copyMethod · 0.45
executeWithParamsMethod · 0.45
isSuccessMethod · 0.45

Tested by 3

TEST_FFunction · 0.68
TEST_FFunction · 0.68
TEST_FFunction · 0.68