sqlite/test/nulls1.test

126 lines
3.3 KiB
Plaintext
Raw Normal View History

# 2019 August 10
#
# 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.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix nulls1
if 1 {
do_execsql_test 1.0 {
DROP TABLE IF EXISTS t3;
CREATE TABLE t3(a INTEGER);
INSERT INTO t3 VALUES(NULL), (10), (30), (20), (NULL);
} {}
for {set a 0} {$a < 3} {incr a} {
foreach {tn limit} {
1 ""
2 "LIMIT 10"
} {
do_execsql_test 1.$a.$tn.1 "
SELECT a FROM t3 ORDER BY a nULLS FIRST $limit
" {{} {} 10 20 30}
do_execsql_test 1.$a.$tn.2 "
SELECT a FROM t3 ORDER BY a nULLS LAST $limit
" {10 20 30 {} {}}
do_execsql_test 1.$a.$tn.3 "
SELECT a FROM t3 ORDER BY a DESC nULLS FIRST $limit
" {{} {} 30 20 10}
do_execsql_test 1.$a.$tn.4 "
SELECT a FROM t3 ORDER BY a DESC nULLS LAST $limit
" {30 20 10 {} {}}
}
switch $a {
0 {
execsql { CREATE INDEX i1 ON t3(a) }
}
1 {
execsql { DROP INDEX i1 ; CREATE INDEX i1 ON t3(a DESC) }
}
}
}
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
CREATE TABLE t2(a, b, c);
CREATE INDEX i2 ON t2(a, b);
INSERT INTO t2 VALUES(1, 1, 1);
INSERT INTO t2 VALUES(1, NULL, 2);
INSERT INTO t2 VALUES(1, NULL, 3);
INSERT INTO t2 VALUES(1, 4, 4);
}
do_execsql_test 2.1 {
SELECT * FROM t2 WHERE a=1 ORDER BY b NULLS LAST
} {
1 1 1 1 4 4 1 {} 2 1 {} 3
}
do_execsql_test 2.2 {
SELECT * FROM t2 WHERE a=1 ORDER BY b DESC NULLS FIRST
} {
1 {} 3
1 {} 2
1 4 4
1 1 1
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 3.0 {
CREATE TABLE t1(a, b, c, d, UNIQUE (b));
}
foreach {tn sql err} {
1 { CREATE INDEX i1 ON t1(a ASC NULLS LAST) } LAST
2 { CREATE INDEX i1 ON t1(a ASC NULLS FIRST) } FIRST
3 { CREATE INDEX i1 ON t1(a, b ASC NULLS LAST) } LAST
4 { CREATE INDEX i1 ON t1(a, b ASC NULLS FIRST) } FIRST
5 { CREATE INDEX i1 ON t1(a DESC NULLS LAST) } LAST
6 { CREATE INDEX i1 ON t1(a DESC NULLS FIRST) } FIRST
7 { CREATE INDEX i1 ON t1(a, b DESC NULLS LAST) } LAST
8 { CREATE INDEX i1 ON t1(a, b DESC NULLS FIRST) } FIRST
9 { CREATE TABLE t2(a, b, PRIMARY KEY(a DESC, b NULLS FIRST)) } FIRST
10 { CREATE TABLE t2(a, b, UNIQUE(a DESC NULLS FIRST, b)) } FIRST
11 { INSERT INTO t1 VALUES(1, 2, 3, 4)
ON CONFLICT (b DESC NULLS LAST) DO UPDATE SET a = a+1 } LAST
12 {
CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
INSERT INTO t1 VALUES(1, 2, 3, 4)
ON CONFLICT (b DESC NULLS FIRST) DO UPDATE SET a = a+1;
END
} FIRST
} {
do_catchsql_test 3.1.$tn $sql "1 {unsupported use of NULLS $err}"
}
do_execsql_test 3.2 {
CREATE TABLE first(nulls, last);
INSERT INTO first(last, nulls) VALUES(100,200), (300,400), (200,300);
SELECT * FROM first ORDER BY nulls;
} {
200 100
300 200
400 300
}
finish_test