Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SqliteDataReader[<string>] is Case-Sensitive #24011

Closed
BenKoth opened this issue Jan 28, 2021 · 3 comments · Fixed by #24588
Closed

SqliteDataReader[<string>] is Case-Sensitive #24011

BenKoth opened this issue Jan 28, 2021 · 3 comments · Fixed by #24588
Assignees
Labels
area-adonet-sqlite closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. community-contribution customer-reported type-enhancement
Milestone

Comments

@BenKoth
Copy link

BenKoth commented Jan 28, 2021

The SqliteDataReader lookup when using a string is case-sensitive:
https://docs.microsoft.com/en-us/dotnet/api/microsoft.data.sqlite.sqlitedatareader.item?view=msdata-sqlite-5.0.0#Microsoft_Data_Sqlite_SqliteDataReader_Item_System_String_

Why? This isn't true of any of the other data readers that I've used including the Microsoft SQL Data reader.
https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqldatareader.item?view=dotnet-plat-ext-5.0#System_Data_SqlClient_SqlDataReader_Item_System_String_

To make matters worse, it is case-sensitive to the name of the column in the database, not what you select.

For example, if you have a table in your Sqlite database like the following:

CREATE TABLE test (testId INT)

The following code will error:

using (SqliteCommand command = new SqliteCommand("SELECT testID FROM test", conn))
{
  using (SqliteDataReader reader = command.ExecuteReader();
  {
    while (reader.read())
    {
      int testId = Convert.ToInt32(reader["testID"]);
    }
  } 
}

The lookup needs to use the same case as the table definition, not the query.
Microsoft.Data.Sqlite version: 5.0.2
Target framework: .Net Standard 2.0

@bricelam
Copy link
Contributor

Related to #18861

@bricelam
Copy link
Contributor

bricelam commented Jan 29, 2021

Note that there are queries where the case matters.

SELECT 1 AS "AB", 2 AS "ab"

We should look for an exact match first before falling back to a case-insensitive match.

It's also worth considering whether reader["Ab"] should throw with the above query.

@roji
Copy link
Member

roji commented Jan 31, 2021

We should look for an exact match first before falling back to a case-insensitive match.

That's what Npgsql does.

It's also worth considering whether reader["Ab"] should throw with the above query.

Good question...

@ajcvickers ajcvickers added this to the Backlog milestone Feb 1, 2021
@bricelam bricelam added the good first issue This issue should be relatively straightforward to fix. label Mar 24, 2021
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 12, 2021
@bricelam bricelam modified the milestones: Backlog, 6.0.0 Apr 12, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-preview5 Apr 26, 2021
@ajcvickers ajcvickers added type-enhancement and removed good first issue This issue should be relatively straightforward to fix. labels Apr 28, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-preview5, 6.0.0 Nov 8, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
area-adonet-sqlite closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. community-contribution customer-reported type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants