AryaWu/sqlite
0
1# 2010 September 282#3# The author disclaims copyright to this source code. In place of4# 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 make13# sure that legacy syntax (syntax that is disallowed according to the14# syntax diagrams) is still accepted, so that older databases that use15# that syntax can still be read.16#17 18set testdir [file dirname $argv0]19source $testdir/tester.tcl20 21# Table constraints should be separated by commas, but they do not have22# 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 {UNIQUE constraint failed: t1.a}}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 three40 );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 {CHECK constraint failed: two}}48do_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 two54 );55 INSERT INTO t1 VALUES(1,2,3);56 }57} {}58do_test schema5-1.6 {59 catchsql {INSERT INTO t1 VALUES(1,3,4)}60} {1 {UNIQUE constraint failed: t1.a}}61do_test schema5-1.7 {62 catchsql {INSERT INTO t1 VALUES(10,2,3)}63} {1 {UNIQUE constraint failed: t1.b, t1.c}}64 65 66 67 68 69finish_test70 