pitrou commented on code in PR #14266:
URL: https://github.com/apache/arrow/pull/14266#discussion_r1009666006
##########
cpp/src/arrow/flight/sql/example/sqlite_statement.cc:
##########
@@ -160,10 +169,100 @@ arrow::Result<int> SqliteStatement::Reset() {
sqlite3_stmt* SqliteStatement::GetSqlite3Stmt() const { return stmt_; }
arrow::Result<int64_t> SqliteStatement::ExecuteUpdate() {
- ARROW_RETURN_NOT_OK(Step());
+ while (true) {
+ ARROW_ASSIGN_OR_RAISE(int rc, Step());
+ if (rc == SQLITE_DONE) break;
+ }
return sqlite3_changes(db_);
}
+Status SqliteStatement::SetParameters(
+ std::vector<std::shared_ptr<arrow::RecordBatch>> parameters) {
+ const int num_params = sqlite3_bind_parameter_count(stmt_);
+ for (const auto& batch : parameters) {
+ if (batch->num_columns() != num_params) {
+ return Status::Invalid("Expected ", num_params, " parameters, but got ",
+ batch->num_columns());
+ }
+ }
+ parameters_ = std::move(parameters);
+ auto end = std::remove_if(
+ parameters_.begin(), parameters_.end(),
+ [](const std::shared_ptr<RecordBatch>& batch) { return batch->num_rows()
== 0; });
+ parameters_.erase(end, parameters_.end());
+ return Status::OK();
+}
+
+Status SqliteStatement::Bind(size_t batch_index, int64_t row_index) {
+ if (batch_index >= parameters_.size()) {
+ return Status::IndexError("Cannot bind to batch ", batch_index);
+ }
+ const RecordBatch& batch = *parameters_[batch_index];
+ if (row_index < 0 || row_index >= batch.num_rows()) {
+ return Status::IndexError("Cannot bind to row ", row_index, " in batch ",
+ batch_index);
+ }
+
+ if (sqlite3_clear_bindings(stmt_) != SQLITE_OK) {
+ return Status::Invalid("Failed to reset bindings: ", sqlite3_errmsg(db_));
+ }
+ for (int c = 0; c < batch.num_columns(); ++c) {
+ Array* column = batch.column(c).get();
+ int64_t column_index = row_index;
+ if (column->type_id() == Type::DENSE_UNION) {
+ // Allow polymorphic bindings via union
Review Comment:
Nice, but why not also handle sparse unions?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]