37f3ac8faa
FossilOrigin-Name: 2f7c946c5f25a858167f5193ca06e53310394c8cff15426ab8a1327a1ec835fd
120 lines
3.8 KiB
Plaintext
120 lines
3.8 KiB
Plaintext
# 2021-08-18
|
|
#
|
|
# The author disclaims copyright to this source code. In place of
|
|
# a legal notice, here is a blessing:
|
|
#
|
|
# May you do good and not evil.
|
|
# May you find forgiveness for yourself and forgive others.
|
|
# May you share freely, never taking more than you give.
|
|
#
|
|
#***********************************************************************
|
|
#
|
|
# This file implements regression tests for SQLite library. The
|
|
# focus of this file is testing STRICT tables.
|
|
#
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
set testprefix strict1
|
|
|
|
# STRICT tables have on a limited number of allowed datatypes.
|
|
#
|
|
do_catchsql_test strict1-1.1 {
|
|
CREATE TABLE t1(a) STRICT;
|
|
} {1 {missing datatype for t1.a}}
|
|
do_catchsql_test strict1-1.2 {
|
|
CREATE TABLE t1(a PRIMARY KEY) STRICT, WITHOUT ROWID;
|
|
} {1 {missing datatype for t1.a}}
|
|
do_catchsql_test strict1-1.3 {
|
|
CREATE TABLE t1(a PRIMARY KEY) WITHOUT ROWID, STRICT;
|
|
} {1 {missing datatype for t1.a}}
|
|
do_catchsql_test strict1-1.4 {
|
|
CREATE TABLE t1(a BANJO PRIMARY KEY) WITHOUT ROWID, STRICT;
|
|
} {1 {unknown datatype for t1.a: "BANJO"}}
|
|
do_catchsql_test strict1-1.5 {
|
|
CREATE TABLE t1(a TEXT PRIMARY KEY, b INT, c INTEGER, d REAL, e BLOB, f DATE) strict;
|
|
} {1 {unknown datatype for t1.f: "DATE"}}
|
|
do_catchsql_test strict1-1.6 {
|
|
CREATE TABLE t1(a TEXT PRIMARY KEY, b INT, c INTEGER, d REAL, e BLOB, f TEXT(50)) WITHOUT ROWID, STRICT;
|
|
} {1 {unknown datatype for t1.f: "TEXT(50)"}}
|
|
|
|
do_execsql_test strict1-2.0 {
|
|
CREATE TABLE t1(
|
|
a INT,
|
|
b INTEGER,
|
|
c BLOB,
|
|
d TEXT,
|
|
e REAL
|
|
) STRICT;
|
|
} {}
|
|
ifcapable vtab {
|
|
do_execsql_test strict1-2.0a {
|
|
SELECT strict FROM pragma_table_list('t1');
|
|
} {1}
|
|
}
|
|
do_catchsql_test strict1-2.1 {
|
|
INSERT INTO t1(a) VALUES('xyz');
|
|
} {1 {cannot store TEXT value in INT column t1.a}}
|
|
do_catchsql_test strict1-2.2 {
|
|
INSERT INTO t1(b) VALUES('xyz');
|
|
} {1 {cannot store TEXT value in INTEGER column t1.b}}
|
|
do_catchsql_test strict1-2.3 {
|
|
INSERT INTO t1(c) VALUES('xyz');
|
|
} {1 {cannot store TEXT value in BLOB column t1.c}}
|
|
do_catchsql_test strict1-2.4 {
|
|
INSERT INTO t1(d) VALUES(x'3142536475');
|
|
} {1 {cannot store BLOB value in TEXT column t1.d}}
|
|
do_catchsql_test strict1-2.5 {
|
|
INSERT INTO t1(e) VALUES('xyz');
|
|
} {1 {cannot store TEXT value in REAL column t1.e}}
|
|
|
|
|
|
do_execsql_test strict1-3.1 {
|
|
INSERT INTO t1(a, b) VALUES(1,2),('3','4'),(5.0, 6.0),(null,null);
|
|
SELECT a, b, '|' FROM t1;
|
|
} {1 2 | 3 4 | 5 6 | {} {} |}
|
|
do_catchsql_test strict1-3.2 {
|
|
INSERT INTO t1(a) VALUES(1.2);
|
|
} {1 {cannot store REAL value in INT column t1.a}}
|
|
do_catchsql_test strict1-3.3 {
|
|
INSERT INTO t1(a) VALUES(x'313233');
|
|
} {1 {cannot store BLOB value in INT column t1.a}}
|
|
do_catchsql_test strict1-3.4 {
|
|
INSERT INTO t1(b) VALUES(1.2);
|
|
} {1 {cannot store REAL value in INTEGER column t1.b}}
|
|
do_catchsql_test strict1-3.5 {
|
|
INSERT INTO t1(b) VALUES(x'313233');
|
|
} {1 {cannot store BLOB value in INTEGER column t1.b}}
|
|
|
|
do_execsql_test strict1-4.1 {
|
|
DELETE FROM t1;
|
|
INSERT INTO t1(c) VALUES(x'313233'), (NULL);
|
|
SELECT typeof(c), c FROM t1;
|
|
} {blob 123 null {}}
|
|
do_catchsql_test strict1-4.2 {
|
|
INSERT INTO t1(c) VALUES('456');
|
|
} {1 {cannot store TEXT value in BLOB column t1.c}}
|
|
|
|
do_execsql_test strict1-5.1 {
|
|
DELETE FROM t1;
|
|
INSERT INTO t1(d) VALUES('xyz'),(4),(5.5),(NULL);
|
|
SELECT typeof(d), d FROM t1;
|
|
} {text xyz text 4 text 5.5 null {}}
|
|
do_catchsql_test strict1-5.2 {
|
|
INSERT INTO t1(d) VALUES(x'4567');
|
|
} {1 {cannot store BLOB value in TEXT column t1.d}}
|
|
|
|
do_execsql_test strict1-6.1 {
|
|
DELETE FROM t1;
|
|
INSERT INTO t1(e) VALUES(1),(2.5),('3'),('4.5'),(6.0),(NULL);
|
|
SELECT typeof(e), e FROM t1;
|
|
} {real 1.0 real 2.5 real 3.0 real 4.5 real 6.0 null {}}
|
|
do_catchsql_test strict1-6.2 {
|
|
INSERT INTO t1(e) VALUES('xyz');
|
|
} {1 {cannot store TEXT value in REAL column t1.e}}
|
|
do_catchsql_test strict1-6.3 {
|
|
INSERT INTO t1(e) VALUES(x'3456');
|
|
} {1 {cannot store BLOB value in REAL column t1.e}}
|
|
|
|
finish_test
|