Skip to content

Commit

Permalink
Merge pull request duckdb#9907 from Mytherin/issue8905
Browse files Browse the repository at this point in the history
Fix duckdb#8905 - make duckdb_rows_changed work with both new and deprecated results
  • Loading branch information
Mytherin committed Dec 6, 2023
2 parents 49d871b + 48a5c46 commit 17ff6c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/capi/result-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,21 @@ idx_t duckdb_rows_changed(duckdb_result *result) {
if (!result) {
return 0;
}
if (!duckdb::deprecated_materialize_result(result)) {
auto &result_data = *(reinterpret_cast<duckdb::DuckDBResultData *>(result->internal_data));
if (result_data.result_set_type == duckdb::CAPIResultSetType::CAPI_RESULT_TYPE_DEPRECATED) {
// not a materialized result
return result->__deprecated_rows_changed;
}
auto &materialized = reinterpret_cast<duckdb::MaterializedQueryResult &>(*result_data.result);
if (materialized.properties.return_type != duckdb::StatementReturnType::CHANGED_ROWS) {
// we can only use this function for CHANGED_ROWS result types
return 0;
}
if (materialized.RowCount() != 1 || materialized.ColumnCount() != 1) {
// CHANGED_ROWS should return exactly one row
return 0;
}
return result->__deprecated_rows_changed;
return materialized.GetValue(0, 0).GetValue<uint64_t>();
}

void *duckdb_column_data(duckdb_result *result, idx_t col) {
Expand Down
1 change: 1 addition & 0 deletions test/api/capi/test_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ TEST_CASE("Basic test of C API", "[capi]") {
// NULL selection
result = tester.Query("SELECT a, b FROM test ORDER BY a");
REQUIRE_NO_FAIL(*result);
REQUIRE(result->rows_changed() == 0);
// NULL, 11, 13
REQUIRE(result->IsNull(0, 0));
REQUIRE(result->Fetch<int32_t>(0, 1) == 11);
Expand Down

0 comments on commit 17ff6c0

Please sign in to comment.