SQLite

View Ticket
Login
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: (text/x-fossil-wiki)
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.

<blockquote><pre>
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;
</pre></blockquote>

The expected output is:

<blockquote><pre>
1|replaces row 1
2|generates row 2
</pre></blockquote>

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

<blockquote><pre>
1|generates row 1
1|replaces row 1
</pre></blockquote>

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.