Skip to content

Microsoft.Data.Sqlite: GetValues rejects an array shorter than the row, unlike the IDataRecord contract #39352

Closed

Description

@alaricd

SqliteDataReader.GetValues throws when the array is shorter than the row, where the IDataRecord contract says it copies what fits. (Split out of #39343 so each change can be reviewed on its own.)

What the documentation says

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.

Why this is a bug

The contract explicitly allows a short array and says what happens: the first values.Length columns are copied and that count is returned. Microsoft.Data.Sqlite throws IndexOutOfRangeException instead, so code that reads only the leading columns of a wide row into a fixed-size buffer (valid against SqlClient, Npgsql and MySqlConnector) fails here.

using var reader = connection.ExecuteReader("SELECT 1, 2, 3");
reader.Read();
reader.GetValues(new object[2]);   // IndexOutOfRangeException; documented: copies 2 values, returns 2

The current behaviour is pinned by GetValues_throws_when_too_narrow. I have a small change that follows the documented contract (copy Math.Min(values.Length, FieldCount) values and return that count) and replaces that test; I'll link it here.

Found with https://github.com/pengdows/pengdows.AdoNetApiTest.conformance

Activity

  1. added theissue type on Oct 22, 2026
  2. added this to the 12.0-preview1 milestone on Oct 22, 2026
  3. added a commit that references this issue on Oct 22, 2026
    c1cd96e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions