xref: /sqlite-3.40.0/test/schema5.test (revision aeb281c2)
1# 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);}
33} {1 {column a is not unique}}
34do_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);}
47} {1 {constraint two failed}}
48
49
50
51
52finish_test
53