interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / selectE.test

240 lines · 5782 bytes Raw Blame History
1# 2013-05-07
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 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.
14#
15# Ticket 6709574d2a8d8b9be3a9cb1afbf4ff2de48ea4e7:
16# drh added on 2013-05-06 15:21:16:
17#
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
25# begins.
26#
27# CREATE TABLE t1(a);
28# INSERT INTO t1 VALUES('abc'),('def');
29# CREATE TABLE t2(a);
30# INSERT INTO t2 VALUES('DEF');
31#
32# SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a;
33# .print -----
34# SELECT a FROM (SELECT a FROM t1 EXCEPT SELECT a FROM t2)
35# ORDER BY a COLLATE nocase;
36# .print -----
37# SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a COLLATE nocase;
38#
39# Bisecting shows that this problem was introduced in SQLite version 3.6.0
40# by check-in [8bbfa97837a74ef] on 2008-06-15.
41#
42
43set testdir [file dirname $argv0]
44source $testdir/tester.tcl
45set testprefix selectE
46
47do_test selectE-1.0 {
48 db eval {
49 CREATE TABLE t1(a);
50 INSERT INTO t1 VALUES('abc'),('def'),('ghi');
51 CREATE TABLE t2(a);
52 INSERT INTO t2 VALUES('DEF'),('abc');
53 CREATE TABLE t3(a);
54 INSERT INTO t3 VALUES('def'),('jkl');
55
56 SELECT a FROM t1 EXCEPT SELECT a FROM t2
57 ORDER BY a COLLATE nocase;
58 }
59} {def ghi}
60do_test selectE-1.1 {
61 db eval {
62 SELECT a FROM t2 EXCEPT SELECT a FROM t3
63 ORDER BY a COLLATE nocase;
64 }
65} {abc DEF}
66do_test selectE-1.2 {
67 db eval {
68 SELECT a FROM t2 EXCEPT SELECT a FROM t3
69 ORDER BY a COLLATE binary;
70 }
71} {DEF abc}
72do_test selectE-1.3 {
73 db eval {
74 SELECT a FROM t2 EXCEPT SELECT a FROM t3
75 ORDER BY a;
76 }
77} {DEF abc}
78
79do_execsql_test selectE-1.4 {
80 WITH xyz AS (
81 SELECT a FROM t2 EXCEPT SELECT a FROM t3 ORDER BY a
82 )
83 SELECT * FROM xyz;
84} {DEF abc}
85
86do_execsql_test selectE-1.5 {
87 WITH xyz AS (
88 SELECT a FROM t2 EXCEPT SELECT a FROM t3 ORDER BY a COLLATE nocase
89 )
90 SELECT * FROM xyz;
91} {abc DEF}
92
93do_execsql_test selectE-1.6 {
94 CREATE VIEW v1 AS SELECT a FROM t2 EXCEPT SELECT a FROM t3 ORDER BY a;
95 SELECT * FROM v1;
96} {DEF abc}
97
98do_execsql_test selectE-1.7 {
99 CREATE VIEW v2 AS
100 SELECT a FROM t2 EXCEPT SELECT a FROM t3 ORDER BY a COLLATE nocase;
101 SELECT * FROM v2;
102} {abc DEF}
103
104do_test selectE-2.1 {
105 db eval {
106 DELETE FROM t2;
107 DELETE FROM t3;
108 INSERT INTO t2 VALUES('ABC'),('def'),('GHI'),('jkl');
109 INSERT INTO t3 SELECT lower(a) FROM t2;
110 SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
111 ORDER BY 1
112 }
113} {}
114do_test selectE-2.2 {
115 db eval {
116 SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
117 ORDER BY 1 COLLATE binary
118 }
119} {}
120
121do_catchsql_test selectE-3.1 {
122 SELECT 1 EXCEPT SELECT 2 ORDER BY 1 COLLATE nocase EXCEPT SELECT 3;
123} {1 {ORDER BY clause should come after EXCEPT not before}}
124
125#-------------------------------------------------------------------------
126#
127reset_db
128do_execsql_test 4.0 {
129 CREATE TABLE t1(a);
130 CREATE TABLE t2(a);
131 INSERT INTO t1 VALUES ('def');
132 INSERT INTO t2 VALUES ('DEF');
133}
134
135do_execsql_test 4.1 {
136 WITH c AS MATERIALIZED (
137 SELECT a FROM t1
138 EXCEPT SELECT a FROM t2
139 ORDER BY a COLLATE nocase
140 )
141 SELECT * FROM c;
142} {def}
143
144do_execsql_test 4.2 {
145 SELECT a FROM t1
146 EXCEPT SELECT a FROM t2
147 ORDER BY a COLLATE nocase
148} {def}
149
150do_execsql_test 4.3 {
151 CREATE VIEW vvv AS
152 SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a COLLATE nocase;
153 SELECT * FROM vvv;
154} {def}
155
156#-------------------------------------------------------------------------
157reset_db
158
159do_execsql_test 5.0 {
160 CREATE TABLE t1(a);
161 INSERT INTO t1 VALUES(2), (3), (4), (5);
162}
163
164do_execsql_test 5.1.1 {
165 SELECT a FROM t1
166 EXCEPT
167 SELECT count(*) FROM t1 GROUP BY (a%2)
168 ORDER BY 1
169} {3 4 5}
170
171do_execsql_test 5.1.2 {
172 SELECT a FROM t1
173 EXCEPT
174 SELECT count(*) FROM t1 GROUP BY (a%2)
175 ORDER BY 1 COLLATE nocase
176} {3 4 5}
177
178do_execsql_test 5.2.1 {
179 SELECT count(*) FROM t1 GROUP BY (a%2)
180 INTERSECT
181 SELECT a FROM t1
182 ORDER BY 1
183} {2}
184
185do_execsql_test 5.2.2 {
186 SELECT count(*) FROM t1 GROUP BY (a%2)
187 INTERSECT
188 SELECT a FROM t1
189 ORDER BY 1 COLLATE nocase
190} {2}
191
192do_execsql_test 5.3.1 {
193 SELECT (a * 2) FROM t1
194 INTERSECT
195 SELECT sum(a) FROM t1 GROUP BY (a%2) HAVING sum(a)>7
196 ORDER BY 1
197} {8}
198
199do_execsql_test 5.3.2 {
200 SELECT (a * 2) FROM t1
201 INTERSECT
202 SELECT sum(a) FROM t1 GROUP BY (a%2) HAVING sum(a)>7
203 ORDER BY 1 COLLATE nocase
204} {8}
205
206do_execsql_test 5.4.1 {
207 SELECT a FROM t1
208 INTERSECT
209 SELECT DISTINCT a FROM t1
210 ORDER BY 1
211} {2 3 4 5}
212
213do_execsql_test 5.4.2 {
214 SELECT a FROM t1
215 INTERSECT
216 SELECT DISTINCT a FROM t1
217 ORDER BY 1 COLLATE nocase
218} {2 3 4 5}
219
220do_execsql_test 5.5.1 {
221 SELECT a FROM t1
222 UNION
223 SELECT 9
224 UNION ALL
225 SELECT DISTINCT a FROM t1
226 ORDER BY 1
227} {2 2 3 3 4 4 5 5 9}
228
229do_execsql_test 5.5.2 {
230 SELECT a FROM t1
231 UNION
232 SELECT 9
233 UNION ALL
234 SELECT DISTINCT a FROM t1
235 ORDER BY 1 COLLATE nocase
236} {2 2 3 3 4 4 5 5 9}
237
238finish_test
239
240