1# 2021-08-18 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 implements regression tests for SQLite library. The 13# focus of this file is testing STRICT tables. 14# 15 16set testdir [file dirname $argv0] 17source $testdir/tester.tcl 18set testprefix strict1 19 20# STRICT tables have on a limited number of allowed datatypes. 21# 22do_catchsql_test strict1-1.1 { 23 CREATE TABLE t1(a) STRICT; 24} {1 {missing datatype for t1.a}} 25do_catchsql_test strict1-1.2 { 26 CREATE TABLE t1(a PRIMARY KEY) STRICT, WITHOUT ROWID; 27} {1 {missing datatype for t1.a}} 28do_catchsql_test strict1-1.3 { 29 CREATE TABLE t1(a PRIMARY KEY) WITHOUT ROWID, STRICT; 30} {1 {missing datatype for t1.a}} 31do_catchsql_test strict1-1.4 { 32 CREATE TABLE t1(a BANJO PRIMARY KEY) WITHOUT ROWID, STRICT; 33} {1 {unknown datatype for t1.a: "BANJO"}} 34do_catchsql_test strict1-1.5 { 35 CREATE TABLE t1(a TEXT PRIMARY KEY, b INT, c INTEGER, d REAL, e BLOB, f DATE) strict; 36} {1 {unknown datatype for t1.f: "DATE"}} 37do_catchsql_test strict1-1.6 { 38 CREATE TABLE t1(a TEXT PRIMARY KEY, b INT, c INTEGER, d REAL, e BLOB, f TEXT(50)) WITHOUT ROWID, STRICT; 39} {1 {unknown datatype for t1.f: "TEXT(50)"}} 40 41do_execsql_test strict1-2.0 { 42 CREATE TABLE t1( 43 a INT, 44 b INTEGER, 45 c BLOB, 46 d TEXT, 47 e REAL 48 ) STRICT; 49 SELECT strict FROM pragma_table_list('t1'); 50} {1} 51do_catchsql_test strict1-2.1 { 52 INSERT INTO t1(a) VALUES('xyz'); 53} {1 {cannot store TEXT value in INT column t1.a}} 54do_catchsql_test strict1-2.2 { 55 INSERT INTO t1(b) VALUES('xyz'); 56} {1 {cannot store TEXT value in INTEGER column t1.b}} 57do_catchsql_test strict1-2.3 { 58 INSERT INTO t1(c) VALUES('xyz'); 59} {1 {cannot store TEXT value in BLOB column t1.c}} 60do_catchsql_test strict1-2.4 { 61 INSERT INTO t1(d) VALUES(x'3142536475'); 62} {1 {cannot store BLOB value in TEXT column t1.d}} 63do_catchsql_test strict1-2.5 { 64 INSERT INTO t1(e) VALUES('xyz'); 65} {1 {cannot store TEXT value in REAL column t1.e}} 66 67 68do_execsql_test strict1-3.1 { 69 INSERT INTO t1(a, b) VALUES(1,2),('3','4'),(5.0, 6.0),(null,null); 70 SELECT a, b, '|' FROM t1; 71} {1 2 | 3 4 | 5 6 | {} {} |} 72do_catchsql_test strict1-3.2 { 73 INSERT INTO t1(a) VALUES(1.2); 74} {1 {cannot store REAL value in INT column t1.a}} 75do_catchsql_test strict1-3.3 { 76 INSERT INTO t1(a) VALUES(x'313233'); 77} {1 {cannot store BLOB value in INT column t1.a}} 78do_catchsql_test strict1-3.4 { 79 INSERT INTO t1(b) VALUES(1.2); 80} {1 {cannot store REAL value in INTEGER column t1.b}} 81do_catchsql_test strict1-3.5 { 82 INSERT INTO t1(b) VALUES(x'313233'); 83} {1 {cannot store BLOB value in INTEGER column t1.b}} 84 85do_execsql_test strict1-4.1 { 86 DELETE FROM t1; 87 INSERT INTO t1(c) VALUES(x'313233'), (NULL); 88 SELECT typeof(c), c FROM t1; 89} {blob 123 null {}} 90do_catchsql_test strict1-4.2 { 91 INSERT INTO t1(c) VALUES('456'); 92} {1 {cannot store TEXT value in BLOB column t1.c}} 93 94do_execsql_test strict1-5.1 { 95 DELETE FROM t1; 96 INSERT INTO t1(d) VALUES('xyz'),(4),(5.5),(NULL); 97 SELECT typeof(d), d FROM t1; 98} {text xyz text 4 text 5.5 null {}} 99do_catchsql_test strict1-5.2 { 100 INSERT INTO t1(d) VALUES(x'4567'); 101} {1 {cannot store BLOB value in TEXT column t1.d}} 102 103do_execsql_test strict1-6.1 { 104 DELETE FROM t1; 105 INSERT INTO t1(e) VALUES(1),(2.5),('3'),('4.5'),(6.0),(NULL); 106 SELECT typeof(e), e FROM t1; 107} {real 1.0 real 2.5 real 3.0 real 4.5 real 6.0 null {}} 108do_catchsql_test strict1-6.2 { 109 INSERT INTO t1(e) VALUES('xyz'); 110} {1 {cannot store TEXT value in REAL column t1.e}} 111do_catchsql_test strict1-6.3 { 112 INSERT INTO t1(e) VALUES(x'3456'); 113} {1 {cannot store BLOB value in REAL column t1.e}} 114 115finish_test 116