SQLProvider icon indicating copy to clipboard operation
SQLProvider copied to clipboard

sqlite - ``Create(...)`` function is incorrect

Open johnW-ret opened this issue 10 months ago • 1 comments

Create(...) function is missing NOT NULL columns - which does indeed result in a

Error: SQLite Error 19: 'NOT NULL constraint failed: kanji_service_attributes.ServiceName'.

during runtime.

Schema:

create table if not exists kanji (
    Id INTEGER PRIMARY KEY AUTOINCREMENT,
    Text TEXT NOT NULL,
    CreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP
);

create table if not exists kanji_service_attributes (
    ServiceName TEXT NOT NULL,
    State INTEGER NOT NULL,
    KanjiId INTEGER NOT NULL,
    FOREIGN KEY (KanjiId) REFERENCES kanji(Id),
    PRIMARY KEY (ServiceName, State)
);

Create(...) members:

ctx.Main.Kanji.``Create(Text)`` // 👍
ctx.Main.KanjiServiceAttributes.``Create(KanjiId)`` // 😱

Intentionally brief issue for lack of time but I can create a full repro for ease of debugging later. Would appreciate if someone could give me a sanity check before I create the full repro to make sure it's not just me forgetting how Sqlite works.

johnW-ret avatar Feb 12 '25 01:02 johnW-ret

Yes it probably expects the primary key to be auto-inserted. The correct way would be let itm = ctx.Main.KanjiServiceAttributes.``Create(KanjiId, ServiceName, State)`` As a work-around should you can do itm.ServiceName <- manually, but that's not optimal.

Thorium avatar Feb 12 '25 14:02 Thorium