SQLite

View Ticket
Login
2017-05-01
18:35 Fixed ticket [f68dc596]: Database corruption on REPLACE with a mix of NULL and non-NULL rowids. plus 5 other changes (artifact: f8f6c4c1 user: drh)
18:12
Clear the BTCF_ValidNKey flag set if a cursor is moved by sqlite3BtreeInsert(). Fix for [f68dc596c4]. (check-in: a6727eef user: dan tags: trunk)
18:09 New ticket [f68dc596] Database corruption on REPLACE with a mix of NULL and non-NULL rowids.. (artifact: 784838a8 user: drh)

Ticket Hash: f68dc596c4e6018d64a0451c7fb747e160e770a0
Title: Database corruption on REPLACE with a mix of NULL and non-NULL rowids.
Status: Fixed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2017-05-01 18:35:39
Version Found In: 3.18.0
User Comments:
drh added on 2017-05-01 18:09:20:

The following SQL might cause an assertion fault. If it does not, it results in two rows of the t table having the same rowid, which is database corruption.

CREATE TABLE t(i INTEGER PRIMARY KEY, a TEXT);
INSERT INTO t VALUES (NULL, 'generates row 1');
REPLACE INTO t VALUES (NULL, 'generates row 2'), (1, 'replaces row 1');
SELECT * FROM t;

The expected output is:

1|replaces row 1
2|generates row 2

The output generated (if there is no assertion fault) is:

1|generates row 1
1|replaces row 1

This problem has existed in the code since version 3.8.4 (2014-03-10). The problem was reported on the mailing list by E. Pasma.