Skip to content

GetValues copies only what the array holds - #376

Merged
Giorgi merged 2 commits into
Giorgi:developfrom
pengdows:fix/getvalues-short-array
Oct 20, 2026
Merged

Giorgi merged 2 commits into
Giorgi:developfrom
pengdows:fix/getvalues-short-array

Conversation

@alaricd

@alaricd alaricd commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

DuckDBDataReader.GetValues(object[]) writes FieldCount values whatever the array's length, so an array shorter than the row throws IndexOutOfRangeException.

The contract

IDataRecord.GetValues, Remarks:

You can pass an Object array that contains fewer than the number of columns that are contained in the resulting row. Only the amount of data the Object array holds is copied to the array. You can also pass an Object array whose length is more than the number of columns that are contained in the resulting row.

Change

Copy Math.Min(values.Length, FieldCount) values and return that count. A longer array was already handled. The new test checks both cases (GetValuesCopiesOnlyWhatTheArrayHolds), and the full suite passes.

Conformance test: GetValues_copies_only_what_fits_when_the_array_is_shorter.

Found by the pengdows ADO.NET conformance suite, which runs the documented System.Data.Common contract against every provider; each failure it reports cites the learn.microsoft.com sentence the provider departs from.

🤖 Generated with Claude Code

IDataRecord.GetValues: "You can pass an Object array that contains
fewer than the number of columns that are contained in the resulting
row. Only the amount of data the Object array holds is copied to the
array." A shorter array threw IndexOutOfRangeException.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 39416786400

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.07%) to 92.553%

Details

  • Coverage increased (+0.07%) from the base build.
  • Patch coverage: 3 of 3 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4013
Covered Lines: 3777
Line Coverage: 94.12%
Relevant Branches: 2285
Covered Branches: 2052
Branch Coverage: 89.8%
Branches in Coverage %: Yes
Coverage Strength: 1004398.59 hits per line

💛 - Coveralls

@Giorgi

Giorgi commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Thanks, the fix looks right. I compared it with Npgsql 10.0.0 against PostgreSQL 18.3 on SELECT 1 AS a, 2 AS b, 3 AS c: GetValues(new object[2]) returns 2 with [1, 2], and GetValues(new object[0]) returns 0, which is what this change does too.

One more difference, though: GetValues(null) throws ArgumentNullException (parameter values) in Npgsql, but NullReferenceException in DuckDB.NET, both before and after this change. Could you add a null check at the start?

public override int GetValues(object[] values)
{
    ArgumentNullException.ThrowIfNull(values);
    CheckRowRead();
    ...

And two small things for the test:

  • cover an empty array (reader.GetValues(new object[0]).Should().Be(0)) and the null case (reader.Invoking(r => r.GetValues(null)).Should().Throw<ArgumentNullException>());
  • the test file now ends with an extra blank line after the closing }.

@Giorgi
Giorgi merged commit ccd94e1 into Giorgi:develop Oct 20, 2026
6 of 8 checks passed
@alaricd

alaricd commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

The requested null check and empty-array coverage are already committed, including the null ArgumentNullException assertion. Thanks for the review.

This branch is waiting to be deployed

1 waiting deployment
external — 07853b63 Waiting Oct 20, 2026 by alaricd via Authorize #688
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants