4 # The author disclaims copyright to this source code. In place of
5 # a legal notice, here is a blessing:
7 # May you do good and not evil.
8 # May you find forgiveness for yourself and forgive others.
9 # May you share freely, never taking more than you give.
11 #***********************************************************************
12 # This file implements regression tests for SQLite library. The
13 # focus of this script is making sure collations pass through the
16 # 2015-02-09: Added tests to make sure COLLATE passes through function
17 # calls. Ticket [ca0d20b6cdddec5e81b8d66f89c46a5583b5f6f6].
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
23 do_test collate8-1.1 {
25 CREATE TABLE t1(a TEXT COLLATE nocase);
26 INSERT INTO t1 VALUES('aaa');
27 INSERT INTO t1 VALUES('BBB');
28 INSERT INTO t1 VALUES('ccc');
29 INSERT INTO t1 VALUES('DDD');
30 SELECT a FROM t1 ORDER BY a;
33 do_test collate8-1.2 {
35 SELECT rowid FROM t1 WHERE a<'ccc' ORDER BY 1
38 do_test collate8-1.3 {
40 SELECT rowid FROM t1 WHERE a<'ccc' COLLATE binary ORDER BY 1
43 do_test collate8-1.4 {
45 SELECT rowid FROM t1 WHERE +a<'ccc' ORDER BY 1
48 do_test collate8-1.5 {
50 SELECT a FROM t1 ORDER BY +a
53 do_test collate8-1.11 {
55 SELECT a AS x FROM t1 ORDER BY "x";
58 do_test collate8-1.12 {
60 SELECT a AS x FROM t1 WHERE x<'ccc' ORDER BY 1
63 do_test collate8-1.13 {
65 SELECT a AS x FROM t1 WHERE x<'ccc' COLLATE binary ORDER BY [x]
68 do_test collate8-1.14 {
70 SELECT a AS x FROM t1 WHERE +x<'ccc' ORDER BY 1
73 do_test collate8-1.15 {
75 SELECT a AS x FROM t1 ORDER BY +x
80 # When a result-set column is aliased into a WHERE clause, make sure the
81 # collating sequence logic works correctly.
83 do_test collate8-2.1 {
86 INSERT INTO t2 VALUES('abc');
87 INSERT INTO t2 VALUES('ABC');
88 SELECT a AS x FROM t2 WHERE x='abc';
91 do_test collate8-2.2 {
93 SELECT a AS x FROM t2 WHERE x='abc' COLLATE nocase;
96 do_test collate8-2.3 {
98 SELECT a AS x FROM t2 WHERE (x COLLATE nocase)='abc';
101 do_test collate8-2.4 {
103 SELECT a COLLATE nocase AS x FROM t2 WHERE x='abc';
106 do_test collate8-2.5 {
108 SELECT a COLLATE nocase AS x FROM t2 WHERE (x COLLATE binary)='abc';
111 do_test collate8-2.6 {
113 SELECT a COLLATE nocase AS x FROM t2 WHERE x='abc' COLLATE binary;
116 do_test collate8-2.7 {
118 SELECT * FROM t2 WHERE (a COLLATE nocase)='abc' COLLATE binary;
121 do_test collate8-2.8 {
123 SELECT a COLLATE nocase AS x FROM t2 WHERE 'abc'=x COLLATE binary;
127 # Make sure the COLLATE operator perculates up through function calls
128 # and other Expr structures that use the Expr.x.pList field.
130 do_execsql_test collate8-3.1 {
131 SELECT 'abc'==('ABC'||'') COLLATE nocase;
132 SELECT 'abc'==('ABC'||'' COLLATE nocase);
133 SELECT 'abc'==('ABC'||('' COLLATE nocase));
134 SELECT 'abc'==('ABC'||upper('' COLLATE nocase));
136 do_execsql_test collate8-3.2 {
137 SELECT 'abc'==('ABC'||max('' COLLATE nocase,'' COLLATE binary));
140 # The COLLATE binary is on the left and so takes precedence
141 do_execsql_test collate8-3.3 {
142 SELECT 'abc'==('ABC'||max('' COLLATE binary,'' COLLATE nocase));
145 do_execsql_test collate8-3.4 {
146 SELECT 'abc'==('ABC'||CASE WHEN 1-1=2 THEN '' COLLATE nocase
147 ELSE '' COLLATE binary END);
148 SELECT 'abc'==('ABC'||CASE WHEN 1+1=2 THEN '' COLLATE nocase
149 ELSE '' COLLATE binary END);
151 do_execsql_test collate8-3.5 {
152 SELECT 'abc'==('ABC'||CASE WHEN 1=2 THEN '' COLLATE binary
153 ELSE '' COLLATE nocase END);