blob: 29df3f16f51cc9c729bc82290aa09aa1befe4d0b [file] [log] [blame]
drhaeb281c2012-05-08 11:17:33 +00001# 2010 September 28
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11#
12# This file checks corner cases in the CREATE TABLE syntax to make
13# sure that legacy syntax (syntax that is disallowed according to the
14# syntax diagrams) is still accepted, so that older databases that use
15# that syntax can still be read.
16#
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21# Table constraints should be separated by commas, but they do not have
22# to be.
23#
24do_test schema5-1.1 {
25 db eval {
26 CREATE TABLE t1(a,b,c, PRIMARY KEY(a) UNIQUE (a) CONSTRAINT one);
27 INSERT INTO t1 VALUES(1,2,3);
28 SELECT * FROM t1;
29 }
30} {1 2 3}
31do_test schema5-1.2 {
32 catchsql {INSERT INTO t1 VALUES(1,3,4);}
drhf9c8ce32013-11-05 13:33:55 +000033} {1 {UNIQUE constraint failed: t1.a}}
drhaeb281c2012-05-08 11:17:33 +000034do_test schema5-1.3 {
35 db eval {
36 DROP TABLE t1;
37 CREATE TABLE t1(a,b,c,
38 CONSTRAINT one PRIMARY KEY(a) CONSTRAINT two CHECK(b<10) UNIQUE(b)
39 CONSTRAINT three
40 );
41 INSERT INTO t1 VALUES(1,2,3);
42 SELECT * FROM t1;
43 }
44} {1 2 3}
45do_test schema5-1.4 {
46 catchsql {INSERT INTO t1 VALUES(10,11,12);}
drhf9c8ce32013-11-05 13:33:55 +000047} {1 {CHECK constraint failed: two}}
drhab35eae2012-05-12 18:29:53 +000048do_test schema5-1.5 {
49 db eval {
50 DROP TABLE t1;
51 CREATE TABLE t1(a,b,c,
52 UNIQUE(a) CONSTRAINT one,
53 PRIMARY KEY(b,c) CONSTRAINT two
54 );
55 INSERT INTO t1 VALUES(1,2,3);
56 }
57} {}
58do_test schema5-1.6 {
59 catchsql {INSERT INTO t1 VALUES(1,3,4)}
drhf9c8ce32013-11-05 13:33:55 +000060} {1 {UNIQUE constraint failed: t1.a}}
drhab35eae2012-05-12 18:29:53 +000061do_test schema5-1.7 {
62 catchsql {INSERT INTO t1 VALUES(10,2,3)}
drhf9c8ce32013-11-05 13:33:55 +000063} {1 {UNIQUE constraint failed: t1.b, t1.c}}
drhab35eae2012-05-12 18:29:53 +000064
drhaeb281c2012-05-08 11:17:33 +000065
66
67
68
69finish_test