3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing the CREATE UNIQUE INDEX statement
13 # to verify that ticket 9a6daf340df99ba93c53bcf8fa83d9f28040d2a8
16 # drh added on 2014-07-30 12:33:04:
18 # The CREATE UNIQUE INDEX on the third line below does not fail even
19 # though the x column values are not all unique.
21 # CREATE TABLE t1(x NOT NULL);
22 # INSERT INTO t1 VALUES(1),(2),(2),(3);
23 # CREATE UNIQUE INDEX t1x ON t1(x);
25 # If the index is created before the INSERT, then uniqueness is enforced
26 # at the point of the INSERT. Note that the NOT NULL on the indexed column
27 # seems to be required in order to exhibit this bug.
29 # "PRAGMA integrity_check" does not detect the resulting malformed database.
30 # That might be considered a separate issue.
32 # Bisecting shows that this problem was introduced by the addition of
33 # WITHOUT ROWID support in version 3.8.2, specifically in check-in
34 # [c80e229dd9c1230] on 2013-11-07. This problem was reported on the mailing
35 # list by Pavel Pimenov. and primary keys, and the UNIQUE constraint
39 set testdir [file dirname $argv0]
40 source $testdir/tester.tcl
43 1 {CREATE TABLE t1(x TEXT PRIMARY KEY, y NOT NULL) WITHOUT ROWID}
44 2 {CREATE TABLE t1(x TEXT PRIMARY KEY, y NOT NULL)}
45 3 {CREATE TABLE t1(x TEXT PRIMARY KEY, y) WITHOUT ROWID}
46 4 {CREATE TABLE t1(x TEXT PRIMARY KEY, y)}
49 db eval {DROP TABLE IF EXISTS t1}
51 db eval {INSERT INTO t1(x,y) VALUES(1,1),(2,2),(3,2),(4,3)}
54 catchsql {CREATE UNIQUE INDEX t1y ON t1(y)}
55 } {1 {UNIQUE constraint failed: t1.y}}
59 5 {CREATE TABLE t1(w,x,y NOT NULL,z NOT NULL,PRIMARY KEY(w,x)) WITHOUT ROWID}
60 6 {CREATE TABLE t1(w,x,y NOT NULL,z NOT NULL,PRIMARY KEY(w,x))}
61 7 {CREATE TABLE t1(w,x,y NOT NULL,z,PRIMARY KEY(w,x)) WITHOUT ROWID}
62 8 {CREATE TABLE t1(w,x,y NOT NULL,z,PRIMARY KEY(w,x))}
63 9 {CREATE TABLE t1(w,x,y,z NOT NULL,PRIMARY KEY(w,x)) WITHOUT ROWID}
64 10 {CREATE TABLE t1(w,x,y,z NOT NULL,PRIMARY KEY(w,x))}
65 11 {CREATE TABLE t1(w,x,y,z,PRIMARY KEY(w,x)) WITHOUT ROWID}
66 12 {CREATE TABLE t1(w,x,y,z,PRIMARY KEY(w,x))}
69 db eval {DROP TABLE IF EXISTS t1}
71 db eval {INSERT INTO t1(w,x,y,z) VALUES(1,2,3,4),(2,3,3,4)}
74 catchsql {CREATE UNIQUE INDEX t1yz ON t1(y,z)}
75 } {1 {UNIQUE constraint failed: t1.y, t1.z}}