Skip to content

Correct SqliteType inference from string, DateOnly, TimeOnly #27213

Closed

Description

@xinbingyiran

Microsoft.Data.Sqlite 6.0.1
TargetFramework net6.0-windows

当我创建一个字符串类型的SqliteParameter时,我查询它的类型,得到的类型信息是 “SqliteType.Integer”

var p = new Microsoft.Data.Sqlite.SqliteParameter("Name","123");

后来我在源码中定位到了以下位置,这就有点不合适了吧

private static readonly Dictionary<Type, SqliteType> _sqliteTypeMapping =
new()
{
{ typeof(bool), SqliteType.Integer },
{ typeof(byte), SqliteType.Integer },
{ typeof(byte[]), SqliteType.Blob },
{ typeof(char), SqliteType.Text },
{ typeof(DateTime), SqliteType.Text },
{ typeof(DateTimeOffset), SqliteType.Text },
{ typeof(DBNull), SqliteType.Text },
{ typeof(decimal), SqliteType.Text },
{ typeof(double), SqliteType.Real },
{ typeof(float), SqliteType.Real },
{ typeof(Guid), SqliteType.Text },
{ typeof(int), SqliteType.Integer },
{ typeof(long), SqliteType.Integer },
{ typeof(sbyte), SqliteType.Integer },
{ typeof(short), SqliteType.Integer },
{ typeof(string), SqliteType.Integer },
{ typeof(TimeSpan), SqliteType.Text },
{ typeof(uint), SqliteType.Integer },
{ typeof(ulong), SqliteType.Integer },
{ typeof(ushort), SqliteType.Integer }
};

Activity

  1. roji commented on Jan 19, 2022

    @roji
    Member

    Google Translate:

    When I create a SqliteParameter of type string, I query its type, and the type info I get is "SqliteType.Integer"
    ...
    Later, I located the following location in the source code, which is a bit inappropriate.
    

    /cc @bricelam

  2. added
    good first issue
    on Jan 21, 2022
  3. self-assigned this
    on Jan 21, 2022
  4. added this to the 7.0.0 milestone on Jan 22, 2022
  5. assigned and unassigned
    and
    roji
    on Feb 23, 2022
  6. changed the title [-]string 类型参数 获取到的SqliteType是Integer[/-] [+]Correct SqliteType inference from string, DateOnly, TimeOnly[/+] on Feb 23, 2022
  7. modified the milestones: 7.0.0, on Mar 31, 2022
  8. modified the milestones: 7.0.0, on Jun 20, 2022
  9. modified the milestones: , 7.0.0 on Nov 5, 2022
  10. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-adonet-sqlitecommunity-contributioncustomer-reportedgood first issue

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions