Skip to content

Throw IndexOutOfRangeException from SqliteDataReader.GetOrdinal for an unknown name - #39353

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
pengdows:sqlite-getordinal-indexoutofrange
Oct 22, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
pengdows:sqlite-getordinal-indexoutofrange

Conversation

@alaricd

@alaricd alaricd commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #39343

SqliteDataReader.GetOrdinal throws ArgumentOutOfRangeException for a name that matches no column; it now throws IndexOutOfRangeException with the name as the message. The exact-match lookup, the case-insensitive fallback and the ambiguous-name InvalidOperationException are unchanged.

What the documentation says

IDataRecord.GetOrdinal, Remarks:

If the index of the named field is not found, an IndexOutOfRangeException is thrown.

Why this is a bug

The exception type is the documented contract. ArgumentOutOfRangeException is an ArgumentException, not an IndexOutOfRangeException, so catch (IndexOutOfRangeException) around an optional-column probe does not catch it.

Tests

  • GetOrdinal_throws_when_out_of_range now expects IndexOutOfRangeException with the name in the message.
  • Microsoft.Data.Sqlite.Tests: 784 passed, 0 failed (7 skipped).

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

This is the GetOrdinal half of #39344, which I'm closing in favour of one PR per change; the GetValues half is #39352 / its own PR.

Checklist

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

🤖 Generated with Claude Code

…n unknown name

GetOrdinal threw ArgumentOutOfRangeException when no column matched.
IDataRecord.GetOrdinal: "If the index of the named field is not found, an
IndexOutOfRangeException is thrown." The exact-match lookup, the
case-insensitive fallback and the ambiguous-name InvalidOperationException
are unchanged.

Fixes dotnet#39343

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

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The documented exception behavior is implemented and covered by tests; only a minor assertion-strengthening nit remains.

No open issues 🎉

What changed in this PR

This pull request updates SqliteDataReader.GetOrdinal to throw the documented IndexOutOfRangeException when a requested column name is not found.

Changes:

  • Replaces ArgumentOutOfRangeException with IndexOutOfRangeException.
  • Preserves the requested column name as the exception message.
  • Updates regression coverage for the exception contract.
File Description
test/​Microsoft.Data.Sqlite.Tests/​SqliteDataReaderTest.cs Verifies the new exception type and message; an exact message assertion is recommended as a minor nit.
src/​Microsoft.Data.Sqlite.Core/​SqliteDataRecord.cs Implements the corrected exception behavior for unknown column names.

Review effort: Lite

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit 80e7f83 into dotnet:main Oct 22, 2026
20 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 23, 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

3 participants