xref: /sqlite-3.40.0/test/selectE.test (revision a43f02ef)
1c01b7306Sdrh# 2013-05-07
2c01b7306Sdrh#
3c01b7306Sdrh# The author disclaims copyright to this source code.  In place of
4c01b7306Sdrh# a legal notice, here is a blessing:
5c01b7306Sdrh#
6c01b7306Sdrh#    May you do good and not evil.
7c01b7306Sdrh#    May you find forgiveness for yourself and forgive others.
8c01b7306Sdrh#    May you share freely, never taking more than you give.
9c01b7306Sdrh#
10c01b7306Sdrh#***********************************************************************
11c01b7306Sdrh# This file implements regression tests for compound SELECT statements
12c01b7306Sdrh# that have ORDER BY clauses with collating sequences that differ
13c01b7306Sdrh# from the collating sequence used for comparison in the compound.
14c01b7306Sdrh#
15c01b7306Sdrh# Ticket 6709574d2a8d8b9be3a9cb1afbf4ff2de48ea4e7:
16c01b7306Sdrh# drh added on 2013-05-06 15:21:16:
17c01b7306Sdrh#
18c01b7306Sdrh# In the code shown below (which is intended to be run from the
19c01b7306Sdrh# sqlite3.exe command-line tool) the three SELECT statements should all
20c01b7306Sdrh# generate the same answer. But the third one does not. It is as if the
21c01b7306Sdrh# COLLATE clause on the ORDER BY somehow got pulled into the EXCEPT
22c01b7306Sdrh# operator. Note that the ".print" commands are instructions to the
23c01b7306Sdrh# sqlite3.exe shell program to output delimiter lines so that you can more
24c01b7306Sdrh# easily tell where the output of one query ends and the next query
25c01b7306Sdrh# begins.
26c01b7306Sdrh#
27c01b7306Sdrh#     CREATE TABLE t1(a);
28c01b7306Sdrh#     INSERT INTO t1 VALUES('abc'),('def');
29c01b7306Sdrh#     CREATE TABLE t2(a);
30c01b7306Sdrh#     INSERT INTO t2 VALUES('DEF');
31c01b7306Sdrh#
32c01b7306Sdrh#     SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a;
33c01b7306Sdrh#     .print -----
34c01b7306Sdrh#     SELECT a FROM (SELECT a FROM t1 EXCEPT SELECT a FROM t2)
35c01b7306Sdrh#      ORDER BY a COLLATE nocase;
36c01b7306Sdrh#     .print -----
37c01b7306Sdrh#     SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a COLLATE nocase;
38c01b7306Sdrh#
39c01b7306Sdrh# Bisecting shows that this problem was introduced in SQLite version 3.6.0
40c01b7306Sdrh# by check-in [8bbfa97837a74ef] on 2008-06-15.
41c01b7306Sdrh#
42c01b7306Sdrh
43c01b7306Sdrhset testdir [file dirname $argv0]
44c01b7306Sdrhsource $testdir/tester.tcl
45c01b7306Sdrh
46c01b7306Sdrhdo_test selectE-1.0 {
47c01b7306Sdrh  db eval {
48c01b7306Sdrh    CREATE TABLE t1(a);
49c01b7306Sdrh    INSERT INTO t1 VALUES('abc'),('def'),('ghi');
50c01b7306Sdrh    CREATE TABLE t2(a);
51c01b7306Sdrh    INSERT INTO t2 VALUES('DEF'),('abc');
52c01b7306Sdrh    CREATE TABLE t3(a);
53c01b7306Sdrh    INSERT INTO t3 VALUES('def'),('jkl');
54c01b7306Sdrh
55c01b7306Sdrh    SELECT a FROM t1 EXCEPT SELECT a FROM t2
56c01b7306Sdrh     ORDER BY a COLLATE nocase;
57c01b7306Sdrh  }
58c01b7306Sdrh} {def ghi}
59c01b7306Sdrhdo_test selectE-1.1 {
60c01b7306Sdrh  db eval {
61c01b7306Sdrh    SELECT a FROM t2 EXCEPT SELECT a FROM t3
62c01b7306Sdrh     ORDER BY a COLLATE nocase;
63c01b7306Sdrh  }
64c01b7306Sdrh} {abc DEF}
65c01b7306Sdrhdo_test selectE-1.2 {
66c01b7306Sdrh  db eval {
67c01b7306Sdrh    SELECT a FROM t2 EXCEPT SELECT a FROM t3
68c01b7306Sdrh     ORDER BY a COLLATE binary;
69c01b7306Sdrh  }
70c01b7306Sdrh} {DEF abc}
71c01b7306Sdrhdo_test selectE-1.3 {
72c01b7306Sdrh  db eval {
73c01b7306Sdrh    SELECT a FROM t2 EXCEPT SELECT a FROM t3
74c01b7306Sdrh     ORDER BY a;
75c01b7306Sdrh  }
76c01b7306Sdrh} {DEF abc}
77c01b7306Sdrh
78c01b7306Sdrhdo_test selectE-2.1 {
79c01b7306Sdrh  db eval {
80c01b7306Sdrh    DELETE FROM t2;
81c01b7306Sdrh    DELETE FROM t3;
82c01b7306Sdrh    INSERT INTO t2 VALUES('ABC'),('def'),('GHI'),('jkl');
83c01b7306Sdrh    INSERT INTO t3 SELECT lower(a) FROM t2;
84c01b7306Sdrh    SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
85c01b7306Sdrh     ORDER BY 1
86c01b7306Sdrh  }
87c01b7306Sdrh} {}
88c01b7306Sdrhdo_test selectE-2.2 {
89c01b7306Sdrh  db eval {
90c01b7306Sdrh    SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
91c01b7306Sdrh     ORDER BY 1 COLLATE binary
92c01b7306Sdrh  }
93c01b7306Sdrh} {}
94c01b7306Sdrh
95*a43f02efSdrhdo_catchsql_test selectE-3.1 {
96*a43f02efSdrh  SELECT 1 EXCEPT SELECT 2 ORDER BY 1 COLLATE nocase EXCEPT SELECT 3;
97*a43f02efSdrh} {1 {ORDER BY clause should come after EXCEPT not before}}
98*a43f02efSdrh
99*a43f02efSdrh
100c01b7306Sdrhfinish_test
101