xref: /sqlite-3.40.0/test/schema5.test (revision f9c8ce3c)
1aeb281c2Sdrh# 2010 September 28
2aeb281c2Sdrh#
3aeb281c2Sdrh# The author disclaims copyright to this source code.  In place of
4aeb281c2Sdrh# a legal notice, here is a blessing:
5aeb281c2Sdrh#
6aeb281c2Sdrh#    May you do good and not evil.
7aeb281c2Sdrh#    May you find forgiveness for yourself and forgive others.
8aeb281c2Sdrh#    May you share freely, never taking more than you give.
9aeb281c2Sdrh#
10aeb281c2Sdrh#***********************************************************************
11aeb281c2Sdrh#
12aeb281c2Sdrh# This file checks corner cases in the CREATE TABLE syntax to make
13aeb281c2Sdrh# sure that legacy syntax (syntax that is disallowed according to the
14aeb281c2Sdrh# syntax diagrams) is still accepted, so that older databases that use
15aeb281c2Sdrh# that syntax can still be read.
16aeb281c2Sdrh#
17aeb281c2Sdrh
18aeb281c2Sdrhset testdir [file dirname $argv0]
19aeb281c2Sdrhsource $testdir/tester.tcl
20aeb281c2Sdrh
21aeb281c2Sdrh# Table constraints should be separated by commas, but they do not have
22aeb281c2Sdrh# to be.
23aeb281c2Sdrh#
24aeb281c2Sdrhdo_test schema5-1.1 {
25aeb281c2Sdrh  db eval {
26aeb281c2Sdrh    CREATE TABLE t1(a,b,c, PRIMARY KEY(a) UNIQUE (a) CONSTRAINT one);
27aeb281c2Sdrh    INSERT INTO t1 VALUES(1,2,3);
28aeb281c2Sdrh    SELECT * FROM t1;
29aeb281c2Sdrh  }
30aeb281c2Sdrh} {1 2 3}
31aeb281c2Sdrhdo_test schema5-1.2 {
32aeb281c2Sdrh  catchsql {INSERT INTO t1 VALUES(1,3,4);}
33*f9c8ce3cSdrh} {1 {UNIQUE constraint failed: t1.a}}
34aeb281c2Sdrhdo_test schema5-1.3 {
35aeb281c2Sdrh  db eval {
36aeb281c2Sdrh    DROP TABLE t1;
37aeb281c2Sdrh    CREATE TABLE t1(a,b,c,
38aeb281c2Sdrh        CONSTRAINT one PRIMARY KEY(a) CONSTRAINT two CHECK(b<10) UNIQUE(b)
39aeb281c2Sdrh        CONSTRAINT three
40aeb281c2Sdrh    );
41aeb281c2Sdrh    INSERT INTO t1 VALUES(1,2,3);
42aeb281c2Sdrh    SELECT * FROM t1;
43aeb281c2Sdrh  }
44aeb281c2Sdrh} {1 2 3}
45aeb281c2Sdrhdo_test schema5-1.4 {
46aeb281c2Sdrh  catchsql {INSERT INTO t1 VALUES(10,11,12);}
47*f9c8ce3cSdrh} {1 {CHECK constraint failed: two}}
48ab35eaedSdrhdo_test schema5-1.5 {
49ab35eaedSdrh  db eval {
50ab35eaedSdrh    DROP TABLE t1;
51ab35eaedSdrh    CREATE TABLE t1(a,b,c,
52ab35eaedSdrh       UNIQUE(a) CONSTRAINT one,
53ab35eaedSdrh       PRIMARY KEY(b,c) CONSTRAINT two
54ab35eaedSdrh    );
55ab35eaedSdrh    INSERT INTO t1 VALUES(1,2,3);
56ab35eaedSdrh  }
57ab35eaedSdrh} {}
58ab35eaedSdrhdo_test schema5-1.6 {
59ab35eaedSdrh  catchsql {INSERT INTO t1 VALUES(1,3,4)}
60*f9c8ce3cSdrh} {1 {UNIQUE constraint failed: t1.a}}
61ab35eaedSdrhdo_test schema5-1.7 {
62ab35eaedSdrh  catchsql {INSERT INTO t1 VALUES(10,2,3)}
63*f9c8ce3cSdrh} {1 {UNIQUE constraint failed: t1.b, t1.c}}
64ab35eaedSdrh
65aeb281c2Sdrh
66aeb281c2Sdrh
67aeb281c2Sdrh
68aeb281c2Sdrh
69aeb281c2Sdrhfinish_test
70