3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for compound SELECT statements
12 # that have ORDER BY clauses with collating sequences that differ
13 # from the collating sequence used for comparison in the compound.
15 # Ticket 6709574d2a8d8b9be3a9cb1afbf4ff2de48ea4e7:
16 # drh added on 2013-05-06 15:21:16:
18 # In the code shown below (which is intended to be run from the
19 # sqlite3.exe command-line tool) the three SELECT statements should all
20 # generate the same answer. But the third one does not. It is as if the
21 # COLLATE clause on the ORDER BY somehow got pulled into the EXCEPT
22 # operator. Note that the ".print" commands are instructions to the
23 # sqlite3.exe shell program to output delimiter lines so that you can more
24 # easily tell where the output of one query ends and the next query
28 # INSERT INTO t1 VALUES('abc'),('def');
30 # INSERT INTO t2 VALUES('DEF');
32 # SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a;
34 # SELECT a FROM (SELECT a FROM t1 EXCEPT SELECT a FROM t2)
35 # ORDER BY a COLLATE nocase;
37 # SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a COLLATE nocase;
39 # Bisecting shows that this problem was introduced in SQLite version 3.6.0
40 # by check-in [8bbfa97837a74ef] on 2008-06-15.
43 set testdir [file dirname $argv0]
44 source $testdir/tester.tcl
49 INSERT INTO t1 VALUES('abc'),('def'),('ghi');
51 INSERT INTO t2 VALUES('DEF'),('abc');
53 INSERT INTO t3 VALUES('def'),('jkl');
55 SELECT a FROM t1 EXCEPT SELECT a FROM t2
56 ORDER BY a COLLATE nocase;
61 SELECT a FROM t2 EXCEPT SELECT a FROM t3
62 ORDER BY a COLLATE nocase;
67 SELECT a FROM t2 EXCEPT SELECT a FROM t3
68 ORDER BY a COLLATE binary;
73 SELECT a FROM t2 EXCEPT SELECT a FROM t3
82 INSERT INTO t2 VALUES('ABC'),('def'),('GHI'),('jkl');
83 INSERT INTO t3 SELECT lower(a) FROM t2;
84 SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
90 SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
91 ORDER BY 1 COLLATE binary
95 do_catchsql_test selectE-3.1 {
96 SELECT 1 EXCEPT SELECT 2 ORDER BY 1 COLLATE nocase EXCEPT SELECT 3;
97 } {1 {ORDER BY clause should come after EXCEPT not before}}