1# 2012 August 23 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 SQLite library. 12# 13# This file implements tests for processing aggregate queries with 14# subqueries in which the subqueries hold the aggregate functions 15# or in which the subqueries are themselves aggregate queries 16# 17 18set testdir [file dirname $argv0] 19source $testdir/tester.tcl 20 21do_test aggnested-1.1 { 22 db eval { 23 CREATE TABLE t1(a1 INTEGER); 24 INSERT INTO t1 VALUES(1), (2), (3); 25 CREATE TABLE t2(b1 INTEGER); 26 INSERT INTO t2 VALUES(4), (5); 27 SELECT (SELECT group_concat(a1,'x') FROM t2) FROM t1; 28 } 29} {1x2x3} 30do_test aggnested-1.2 { 31 db eval { 32 SELECT 33 (SELECT group_concat(a1,'x') || '-' || group_concat(b1,'y') FROM t2) 34 FROM t1; 35 } 36} {1x2x3-4y5} 37do_test aggnested-1.3 { 38 db eval { 39 SELECT (SELECT group_concat(b1,a1) FROM t2) FROM t1; 40 } 41} {415 425 435} 42do_test aggnested-1.4 { 43 db eval { 44 SELECT (SELECT group_concat(a1,b1) FROM t2) FROM t1; 45 } 46} {151 252 353} 47 48 49# This test case is a copy of the one in 50# http://www.mail-archive.com/[email protected]/msg70787.html 51# 52do_test aggnested-2.0 { 53 sqlite3 db2 :memory: 54 db2 eval { 55 CREATE TABLE t1 (A1 INTEGER NOT NULL,A2 INTEGER NOT NULL,A3 INTEGER NOT 56 NULL,A4 INTEGER NOT NULL,PRIMARY KEY(A1)); 57 REPLACE INTO t1 VALUES(1,11,111,1111); 58 REPLACE INTO t1 VALUES(2,22,222,2222); 59 REPLACE INTO t1 VALUES(3,33,333,3333); 60 CREATE TABLE t2 (B1 INTEGER NOT NULL,B2 INTEGER NOT NULL,B3 INTEGER NOT 61 NULL,B4 INTEGER NOT NULL,PRIMARY KEY(B1)); 62 REPLACE INTO t2 VALUES(1,88,888,8888); 63 REPLACE INTO t2 VALUES(2,99,999,9999); 64 SELECT (SELECT GROUP_CONCAT(CASE WHEN a1=1 THEN'A' ELSE 'B' END) FROM t2), 65 t1.* 66 FROM t1; 67 } 68} {A,B,B 3 33 333 3333} 69db2 close 70 71finish_test 72