Skip to content

Bug: SQLite Identity field cannot identified #790

@davidrot

Description

@davidrot

Bug Description

Repodb cant determine the IdentityField in the sqlite table when create statement is using " around column names. If using the sql statement below, the code is returning ""Id"" (see picture). This is resulting in issue in BaseStatementBuilder.CreateInsert(), the insertableFields is not excluding the id field.

If you tell me how a potential fix would look like I can prepare a PR.

repodb

Exception Message:

None

Schema and Model:

Please share to us the schema of the table (not actual) that could help us replicate the issue if necessary.

Not working:

CREATE TABLE "User"(
"Id" INTEGER PRIMARY KEY AUTOINCREMENT,
"Username" text,
"Password" text,
"Email" text,
"CreationDate" DATETIME,
"ModificationDate" DATETIME,
"Disabled" integer NOT NULL DEFAULT '0',
"DisabledDate" DATETIME
);

Working

CREATE TABLE User(
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Username text,
Password text,
Email text,
CreationDate DATETIME,
ModificationDate DATETIME,
Disabled integer NOT NULL DEFAULT '0',
DisabledDate DATETIME
);

And also the model that corresponds the schema.

public class User
{
    [Identity]
    public long Id { get; set; }
    public string Username { get; set; }
    public string Password { get; set; }
    public string Email { get; set; }
    public DateTime CreationDate { get; set; }
    public DateTime ModificationDate { get; set; }
    public bool Disabled { get; set; }
    public DateTime? DisabledDate { get; set; }
}

var connectionString = $"Data Source=\"MemoryDb\"; Mode=Memory; Cache=Shared";
var sut = new UserRepository(connectionString);

var item = sut.Insert(new User { Username = "UnitTest" + new Random().Next(0,100000) });

Library Version:

Example: RepoDb v1.12.7 and RepoDb.SqLite v1.1.3

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions