2021-08-18 16:13:58 +03:00
|
|
|
# 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 {
|
2021-08-23 13:28:02 +03:00
|
|
|
CREATE TABLE t1(a) STRICT;
|
|
|
|
} {1 {missing datatype for t1.a}}
|
2021-08-18 16:13:58 +03:00
|
|
|
do_catchsql_test strict1-1.2 {
|
2021-08-23 13:28:02 +03:00
|
|
|
CREATE TABLE t1(a PRIMARY KEY) STRICT, WITHOUT ROWID;
|
|
|
|
} {1 {missing datatype for t1.a}}
|
2021-08-18 16:13:58 +03:00
|
|
|
do_catchsql_test strict1-1.3 {
|
2021-08-23 13:28:02 +03:00
|
|
|
CREATE TABLE t1(a PRIMARY KEY) WITHOUT ROWID, STRICT;
|
|
|
|
} {1 {missing datatype for t1.a}}
|
2021-08-18 16:13:58 +03:00
|
|
|
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)"}}
|
2021-08-18 22:22:27 +03:00
|
|
|
|
|
|
|
do_execsql_test strict1-2.0 {
|
|
|
|
CREATE TABLE t1(
|
|
|
|
a INT,
|
|
|
|
b INTEGER,
|
|
|
|
c BLOB,
|
|
|
|
d TEXT,
|
|
|
|
e REAL
|
|
|
|
) STRICT;
|
2021-10-01 23:39:50 +03:00
|
|
|
} {}
|
|
|
|
ifcapable vtab {
|
|
|
|
do_execsql_test strict1-2.0a {
|
|
|
|
SELECT strict FROM pragma_table_list('t1');
|
|
|
|
} {1}
|
|
|
|
}
|
2021-08-18 22:22:27 +03:00
|
|
|
do_catchsql_test strict1-2.1 {
|
|
|
|
INSERT INTO t1(a) VALUES('xyz');
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store TEXT value in INT column t1.a}}
|
2021-08-18 22:22:27 +03:00
|
|
|
do_catchsql_test strict1-2.2 {
|
|
|
|
INSERT INTO t1(b) VALUES('xyz');
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store TEXT value in INTEGER column t1.b}}
|
2021-08-18 22:22:27 +03:00
|
|
|
do_catchsql_test strict1-2.3 {
|
|
|
|
INSERT INTO t1(c) VALUES('xyz');
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store TEXT value in BLOB column t1.c}}
|
2021-08-18 22:22:27 +03:00
|
|
|
do_catchsql_test strict1-2.4 {
|
|
|
|
INSERT INTO t1(d) VALUES(x'3142536475');
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store BLOB value in TEXT column t1.d}}
|
2021-08-18 22:22:27 +03:00
|
|
|
do_catchsql_test strict1-2.5 {
|
|
|
|
INSERT INTO t1(e) VALUES('xyz');
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store TEXT value in REAL column t1.e}}
|
2021-08-18 22:22:27 +03:00
|
|
|
|
2021-09-21 20:26:23 +03:00
|
|
|
|
2021-08-18 22:22:27 +03:00
|
|
|
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);
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store REAL value in INT column t1.a}}
|
2021-08-18 22:22:27 +03:00
|
|
|
do_catchsql_test strict1-3.3 {
|
|
|
|
INSERT INTO t1(a) VALUES(x'313233');
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store BLOB value in INT column t1.a}}
|
2021-08-18 22:22:27 +03:00
|
|
|
do_catchsql_test strict1-3.4 {
|
|
|
|
INSERT INTO t1(b) VALUES(1.2);
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store REAL value in INTEGER column t1.b}}
|
2021-08-18 22:22:27 +03:00
|
|
|
do_catchsql_test strict1-3.5 {
|
|
|
|
INSERT INTO t1(b) VALUES(x'313233');
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store BLOB value in INTEGER column t1.b}}
|
2021-08-18 22:22:27 +03:00
|
|
|
|
|
|
|
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');
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store TEXT value in BLOB column t1.c}}
|
2021-08-18 22:22:27 +03:00
|
|
|
|
2021-08-19 03:24:43 +03:00
|
|
|
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');
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store BLOB value in TEXT column t1.d}}
|
2021-08-19 03:24:43 +03:00
|
|
|
|
|
|
|
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');
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store TEXT value in REAL column t1.e}}
|
2021-08-19 03:24:43 +03:00
|
|
|
do_catchsql_test strict1-6.3 {
|
|
|
|
INSERT INTO t1(e) VALUES(x'3456');
|
2021-08-20 11:05:42 +03:00
|
|
|
} {1 {cannot store BLOB value in REAL column t1.e}}
|
2021-08-19 03:24:43 +03:00
|
|
|
|
2021-11-03 17:02:48 +03:00
|
|
|
do_execsql_test strict1-7.1 {
|
|
|
|
DROP TABLE IF EXISTS t4;
|
|
|
|
CREATE TABLE t4(
|
|
|
|
a INT AS (b*2) VIRTUAL,
|
|
|
|
b INT AS (c*2) STORED,
|
|
|
|
c INT PRIMARY KEY
|
|
|
|
) STRICT;
|
|
|
|
INSERT INTO t4(c) VALUES(1);
|
|
|
|
SELECT * FROM t4;
|
|
|
|
} {4 2 1}
|
2021-11-03 18:59:17 +03:00
|
|
|
do_catchsql_test strict-7.2 {
|
|
|
|
ALTER TABLE t4 ADD COLUMN d VARCHAR;
|
|
|
|
} {1 {error in table t4 after add column: unknown datatype for t4.d: "VARCHAR"}}
|
|
|
|
do_catchsql_test strict-7.3 {
|
|
|
|
ALTER TABLE t4 ADD COLUMN d;
|
|
|
|
} {1 {error in table t4 after add column: missing datatype for t4.d}}
|
2021-11-03 17:02:48 +03:00
|
|
|
|
2021-08-18 16:13:58 +03:00
|
|
|
finish_test
|