drh | 030796d | 2012-08-23 16:18:10 +0000 | [diff] [blame] | 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 | |
| 18 | set testdir [file dirname $argv0] |
| 19 | source $testdir/tester.tcl |
| 20 | |
| 21 | do_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} |
| 30 | do_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} |
drh | ed551b9 | 2012-08-23 19:46:11 +0000 | [diff] [blame] | 37 | do_test aggnested-1.3 { |
| 38 | db eval { |
| 39 | SELECT (SELECT group_concat(b1,a1) FROM t2) FROM t1; |
| 40 | } |
| 41 | } {415 425 435} |
| 42 | do_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/sqlite-users@sqlite.org/msg70787.html |
| 51 | # |
| 52 | do_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} |
| 69 | db2 close |
drh | 030796d | 2012-08-23 16:18:10 +0000 | [diff] [blame] | 70 | |
| 71 | finish_test |