2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this file is testing the CREATE UNIQUE INDEX statement,
2N/A# and primary keys, and the UNIQUE constraint on table columns
2N/Aset testdir [file dirname $argv0]
2N/A# Try to create a table with two primary keys.
2N/A# (This is allowed in SQLite even that it is not valid SQL)
2N/A} {1 {table "t1" has more than one primary key}}
2N/Ado_test unique-1.1b {
2N/A INSERT INTO t1(a,b,c) VALUES(1,2,3)
2N/A INSERT INTO t1(a,b,c) VALUES(1,3,4)
2N/A} {1 {column a is not unique}}
2N/A SELECT * FROM t1 ORDER BY a;
2N/A INSERT INTO t1(a,b,c) VALUES(3,2,4)
2N/A} {1 {column b is not unique}}
2N/A SELECT * FROM t1 ORDER BY a;
2N/A INSERT INTO t1(a,b,c) VALUES(3,4,5)
2N/A SELECT * FROM t1 ORDER BY a;
2N/Aintegrity_check unique-1.9
2N/A CREATE TABLE t2(a int, b int);
2N/A INSERT INTO t2(a,b) VALUES(1,2);
2N/A INSERT INTO t2(a,b) VALUES(3,4);
2N/A SELECT * FROM t2 ORDER BY a;
2N/A CREATE UNIQUE INDEX i2 ON t2(a)
2N/A SELECT * FROM t2 ORDER BY a
2N/A INSERT INTO t2 VALUES(1,5);
2N/A} {1 {column a is not unique}}
2N/A SELECT * FROM t2 ORDER BY a
2N/A SELECT * FROM t2 ORDER BY a;
2N/A INSERT INTO t2 VALUES(1,5)
2N/A SELECT * FROM t2 ORDER BY a, b;
2N/A CREATE UNIQUE INDEX i2 ON t2(a);
2N/A} {1 {indexed columns are not unique}}
2N/A CREATE INDEX i2 ON t2(a);
2N/Aintegrity_check unique-2.10
2N/A# Test the UNIQUE keyword as used on two or more fields.
2N/A INSERT INTO t3(a,b,c,d) VALUES(1,2,3,4);
2N/A SELECT * FROM t3 ORDER BY a,b,c,d;
2N/A INSERT INTO t3(a,b,c,d) VALUES(1,2,3,5);
2N/A SELECT * FROM t3 ORDER BY a,b,c,d;
2N/A} {0 {1 2 3 4 1 2 3 5}}
2N/A INSERT INTO t3(a,b,c,d) VALUES(1,4,3,5);
2N/A SELECT * FROM t3 ORDER BY a,b,c,d;
2N/A} {1 {columns a, c, d are not unique}}
2N/Aintegrity_check unique-3.5
2N/A# Make sure NULLs are distinct as far as the UNIQUE tests are
2N/A CREATE TABLE t4(a UNIQUE, b, c, UNIQUE(b,c));
2N/A INSERT INTO t4 VALUES(1,2,3);
2N/A INSERT INTO t4 VALUES(NULL, 2, NULL);
2N/A INSERT INTO t4 VALUES(NULL, 3, 4);
2N/A} {1 2 3 {} 2 {} {} 3 4}
2N/A INSERT INTO t4 VALUES(2, 2, NULL);
2N/A} {1 2 3 {} 2 {} {} 3 4 2 2 {}}
2N/Aintegrity_check unique-4.6
2N/A# Test the error message generation logic. In particular, make sure we
2N/A# do not overflow the static buffer used to generate the error message.
2N/A first_column_with_long_name,
2N/A second_column_with_long_name,
2N/A third_column_with_long_name,
2N/A fourth_column_with_long_name,
2N/A fifth_column_with_long_name,
2N/A sixth_column_with_long_name,
2N/A first_column_with_long_name,
2N/A second_column_with_long_name,
2N/A third_column_with_long_name,
2N/A fourth_column_with_long_name,
2N/A fifth_column_with_long_name,
2N/A sixth_column_with_long_name
2N/A INSERT INTO t5 VALUES(1,2,3,4,5,6);
2N/A INSERT INTO t5 VALUES(1,2,3,4,5,6);
2N/A} {1 {columns first_column_with_long_name, second_column_with_long_name, third_column_with_long_name, fourth_column_with_long_name, fifth_column_with_long_name, ... are not unique}}