Skip to content

Bug: [SQLite] PrimaryKey with AUTOINCREMENT not recognized #802

@Kaizer69

Description

@Kaizer69

Bug Description

Hello. With a table created with DBSqlite Browser, after adding a primary key, with or without autoincrement, if the AUTOINCREMENT "specialword" is added on the column, RepoDB recognize the key as a primary key with autoincrement and skip filling the query with ID field.
Instead, with PRIMARY KEY added in the end of table (for example when you have multiple fields for primary key or with default creation of table with DBSqliteBrowser), RepoDb fill the ID with a value (0 for example, because the key is a not null integer, but it will be not valorized), then you get an exception regard duplicate keys.

Exception Message:

Error regard duplicate PrimaryKEY when inserting a new record.

Schema and Model:

CREATE TABLE "Articles" (
"ID" INTEGER NOT NULL UNIQUE,
"ArticleID" TEXT,
"Title" TEXT NOT NULL,
"Description" TEXT,
"Date_Added" INTEGER NOT NULL,
"Date_Fetched" INTEGER,
PRIMARY KEY("ID" AUTOINCREMENT)
)

[Table("Articles")]
public record EArticle {
[Primary]
public int    ID         { get; set; }
public string ArticleID  { get; set; }
public string Title      { get; set; }
public string Description { get; set; }

[PropertyHandler(typeof(DateTimeHandlers))]
public DateTime Date_Added { get; set; }

[PropertyHandler(typeof(DateTimeNullableHandlers))]
public DateTime? Date_Fetched { get; set; }
}

Library Version:

Example: RepoDb v1.12.7 and RepoDb.Sqlite

With that schema it works perfectly

CREATE TABLE "Articles" (
"ID" INTEGER NOT NULL PRIMARY KEY,
"ArticleID" TEXT,
"Title" TEXT NOT NULL,
"Description" TEXT,
"Date_Added" INTEGER NOT NULL,
"Date_Fetched" INTEGER,
)

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