Skip to content

Follow the IDataRecord contract in SqliteDataReader.GetOrdinal and GetValues - #39344

Closed
alaricd wants to merge 1 commit into
dotnet:mainfrom
pengdows:sqlite-getordinal-getvalues-contract
Closed

alaricd wants to merge 1 commit into
dotnet:mainfrom
pengdows:sqlite-getordinal-getvalues-contract

Conversation

@alaricd

@alaricd alaricd commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #39343

Summary

Two SqliteDataReader members depart from the documented IDataRecord contract:

  • GetOrdinal for an unknown name throws ArgumentOutOfRangeException. IDataRecord.GetOrdinal: "If the index of the named field is not found, an IndexOutOfRangeException is thrown." It now throws IndexOutOfRangeException with the name as the message, as SqlClient does. The exact-match lookup, the case-insensitive fallback and the ambiguous-name InvalidOperationException are unchanged.
  • GetValues throws when the array is shorter than the row. 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." It now copies Math.Min(values.Length, FieldCount) values and returns that count.

Tests

  • GetOrdinal_throws_when_out_of_range now expects IndexOutOfRangeException.
  • GetValues_throws_when_too_narrow is replaced by GetValues_copies_only_what_fits_when_too_narrow: a 2-element array for a 3-column row, and an empty array.
  • Microsoft.Data.Sqlite.Tests: 784 passed, 0 failed (7 skipped).

Behaviour change: code catching ArgumentOutOfRangeException from GetOrdinal needs to catch IndexOutOfRangeException.

Checklist

Found by the pengdows ADO.NET conformance suite, which runs the documented System.Data.Common contract against every provider. These two are the only Required tests Microsoft.Data.Sqlite 9.0.5 fails there.

🤖 Generated with Claude Code

…tValues

- GetOrdinal throws IndexOutOfRangeException for an unknown name, as
  IDataRecord.GetOrdinal documents, instead of ArgumentOutOfRangeException
- GetValues copies only as many values as the array holds and returns
  that count, as IDataRecord.GetValues documents, instead of throwing
  for an array shorter than the row

Fixes dotnet#39343

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alaricd

alaricd commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Split into one PR per change so each can be reviewed on its own: #39353 (GetOrdinal throws IndexOutOfRangeException, #39343) and #39354 (GetValues copies only what fits, #39352). Same code and tests as here.

@alaricd alaricd closed this Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Microsoft.Data.Sqlite: GetOrdinal throws ArgumentOutOfRangeException for an unknown name, unlike the IDataRecord contract

1 participant