xref: /sqlite-3.40.0/test/date2.test (revision 6e97f8ec)
1# 2017-07-20
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# This file implements regression tests for SQLite library.  The
12# focus of this file is testing date and time functions used in
13# check constraints and index expressions.
14#
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19# Skip this whole file if date and time functions are omitted
20# at compile-time
21#
22ifcapable {!datetime} {
23  finish_test
24  return
25}
26
27do_execsql_test date2-100 {
28  CREATE TABLE t1(x, y, CHECK( date(x) BETWEEN '2017-07-01' AND '2017-07-31' ));
29  INSERT INTO t1(x,y) VALUES('2017-07-20','one');
30} {}
31do_catchsql_test date2-110 {
32  INSERT INTO t1(x,y) VALUES('now','two');
33} {1 {non-deterministic function in index expression or CHECK constraint}}
34do_execsql_test date2-120 {
35  SELECT * FROM t1;
36} {2017-07-20 one}
37do_catchsql_test date2-130 {
38  INSERT INTO t1(x,y) VALUES('2017-08-01','two');
39} {1 {CHECK constraint failed: t1}}
40
41do_execsql_test date2-200 {
42  CREATE TABLE t2(x,y);
43  INSERT INTO t2(x,y) VALUES(1, '2017-07-20'), (2, 'xyzzy');
44  CREATE INDEX t2y ON t2(date(y));
45}
46do_catchsql_test date2-210 {
47  INSERT INTO t2(x,y) VALUES(3, 'now');
48} {1 {non-deterministic function in index expression or CHECK constraint}}
49do_execsql_test date2-220 {
50  SELECT x, y FROM t2 ORDER BY x;
51} {1 2017-07-20 2 xyzzy}
52
53finish_test
54