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 SQLite library.
13 # $Id: selectC.test,v 1.5 2009/05/17 15:26:21 drh Exp $
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
21 CREATE TABLE t1(a, b, c);
22 INSERT INTO t1 VALUES(1,'aaa','bbb');
23 INSERT INTO t1 SELECT * FROM t1;
24 INSERT INTO t1 VALUES(2,'ccc','ddd');
26 SELECT DISTINCT a AS x, b||c AS y
28 WHERE y IN ('aaabbb','xxx');
33 SELECT DISTINCT a AS x, b||c AS y
35 WHERE b||c IN ('aaabbb','xxx');
40 SELECT DISTINCT a AS x, b||c AS y
47 SELECT DISTINCT a AS x, b||c AS y
54 SELECT DISTINCT a AS x, b||c AS y
61 SELECT DISTINCT a AS x, b||c AS y
68 SELECT DISTINCT a AS x, b||c AS y
75 SELECT a AS x, b||c AS y
83 SELECT a AS x, b||c AS y
89 do_test selectC-1.10 {
91 SELECT a AS x, b||c AS y
97 do_test selectC-1.11 {
99 SELECT a AS x, b||c AS y
105 proc longname_toupper x {return [string toupper $x]}
106 db function uppercaseconversionfunctionwithaverylongname longname_toupper
107 do_test selectC-1.12.1 {
109 SELECT DISTINCT upper(b) AS x
114 do_test selectC-1.12.2 {
116 SELECT DISTINCT uppercaseconversionfunctionwithaverylongname(b) AS x
121 do_test selectC-1.13.1 {
129 do_test selectC-1.13.2 {
131 SELECT uppercaseconversionfunctionwithaverylongname(b) AS x
137 do_test selectC-1.14.1 {
144 do_test selectC-1.14.2 {
146 SELECT uppercaseconversionfunctionwithaverylongname(b) AS x
152 # The following query used to leak memory. Verify that has been fixed.
154 ifcapable trigger&&compound {
155 do_test selectC-2.1 {
157 CREATE TABLE t21a(a,b);
158 INSERT INTO t21a VALUES(1,2);
159 CREATE TABLE t21b(n);
160 CREATE TRIGGER r21 AFTER INSERT ON t21b BEGIN
161 SELECT a FROM t21a WHERE a>new.x UNION ALL
162 SELECT b FROM t21a WHERE b>new.x ORDER BY 1 LIMIT 2;
164 INSERT INTO t21b VALUES(6);
166 } {1 {no such column: new.x}}
169 # Check that ticket [883034dcb5] is fixed.
171 do_test selectC-3.1 {
173 CREATE TABLE person (
174 org_id TEXT NOT NULL,
175 nickname TEXT NOT NULL,
177 CONSTRAINT person_pk PRIMARY KEY (org_id, nickname),
178 CONSTRAINT person_license_uk UNIQUE (license)
180 INSERT INTO person VALUES('meyers', 'jack', '2GAT123');
181 INSERT INTO person VALUES('meyers', 'hill', 'V345FMP');
182 INSERT INTO person VALUES('meyers', 'jim', '2GAT138');
183 INSERT INTO person VALUES('smith', 'maggy', '');
184 INSERT INTO person VALUES('smith', 'jose', 'JJZ109');
185 INSERT INTO person VALUES('smith', 'jack', 'THX138');
186 INSERT INTO person VALUES('lakeside', 'dave', '953OKG');
187 INSERT INTO person VALUES('lakeside', 'amy', NULL);
188 INSERT INTO person VALUES('lake-apts', 'tom', NULL);
189 INSERT INTO person VALUES('acorn', 'hideo', 'CQB421');
193 count((NOT (org_id IS NULL)) AND (NOT (nickname IS NULL)))
195 WHERE (CASE WHEN license != '' THEN 1 ELSE 0 END)
198 } {acorn 1 lakeside 1 meyers 3 smith 2}
199 do_test selectC-3.2 {
201 CREATE TABLE t2(a PRIMARY KEY, b);
202 INSERT INTO t2 VALUES('abc', 'xxx');
203 INSERT INTO t2 VALUES('def', 'yyy');
204 SELECT a, max(b || a) FROM t2 WHERE (b||b||b)!='value' GROUP BY a;
206 } {abc xxxabc def yyydef}
207 do_test selectC-3.3 {
209 SELECT b, max(a || b) FROM t2 WHERE (b||b||b)!='value' GROUP BY a;
211 } {xxx abcxxx yyy defyyy}
214 proc udf {} { incr ::udf }
218 do_execsql_test selectC-4.1 {
219 create table t_distinct_bug (a, b, c);
220 insert into t_distinct_bug values ('1', '1', 'a');
221 insert into t_distinct_bug values ('1', '2', 'b');
222 insert into t_distinct_bug values ('1', '3', 'c');
223 insert into t_distinct_bug values ('1', '1', 'd');
224 insert into t_distinct_bug values ('1', '2', 'e');
225 insert into t_distinct_bug values ('1', '3', 'f');
228 do_execsql_test selectC-4.2 {
229 select a from (select distinct a, b from t_distinct_bug)
232 do_execsql_test selectC-4.3 {
233 select a, udf() from (select distinct a, b from t_distinct_bug)