/ View Ticket
Login
Ticket UUID: 1b266395d6bc1041dbd907194539b2b81b7af1e2
Title: INSERT OR REPLACE with a foreign key constraint leads to assertion fault
Status: Fixed Type: Code_Defect
Severity: Severe Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2015-09-30 14:06:49
Version Found In: 3.8.11.1
User Comments:
drh added on 2015-09-30 12:10:31:

The following script causes an assertion fault:

PRAGMA foreign_keys=1;
CREATE TABLE Foo (Id INTEGER PRIMARY KEY, ParentId INTEGER REFERENCES Foo(Id) ON DELETE CASCADE, C1);
INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (1, null, 'A');
INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (2, 1, 'A-2-1');
INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (3, 2, 'A-3-2');
INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (4, 3, 'A-4-3');
INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (2, 3, 'A-2-3');

This problem appears to have been introduced with version 3.8.4, specifically at check-in [56bc5ce8958c8e625].


drh added on 2015-09-30 12:36:57:

A simpler test case:

PRAGMA foreign_keys=ON;
CREATE TABLE t1(x INTEGER PRIMARY KEY, parent REFERENCES t1 ON DELETE CASCADE);
INSERT INTO t1 VALUES(1, NULL),(2, 1),(3, 2);
INSERT OR REPLACE INTO t1 VALUES(2, 3);