summaryrefslogtreecommitdiff
path: root/test/aggnested.test
diff options
context:
space:
mode:
authorHans-Christoph Steiner <hans@eds.org>2013-01-17 14:23:24 -0500
committerHans-Christoph Steiner <hans@eds.org>2013-01-17 14:23:24 -0500
commit4f9313b1de21a03df32bfba4d94207c78a2171b0 (patch)
tree6a637dd4dde653f870346a37ec6555eb0574949a /test/aggnested.test
parent9da5e9acd37e51b86429d938e7e6a64ffb02da84 (diff)
parent1b5ba8e022836fa8ab93bc90df1b34a29ea6e134 (diff)
Merge tag 'upstream/2.1.1'
Upstream version 2.1.1 Conflicts: .gitignore
Diffstat (limited to 'test/aggnested.test')
-rw-r--r--test/aggnested.test71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/aggnested.test b/test/aggnested.test
new file mode 100644
index 0000000..22f0fb6
--- /dev/null
+++ b/test/aggnested.test
@@ -0,0 +1,71 @@
+# 2012 August 23
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.
+#
+# This file implements tests for processing aggregate queries with
+# subqueries in which the subqueries hold the aggregate functions
+# or in which the subqueries are themselves aggregate queries
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test aggnested-1.1 {
+ db eval {
+ CREATE TABLE t1(a1 INTEGER);
+ INSERT INTO t1 VALUES(1), (2), (3);
+ CREATE TABLE t2(b1 INTEGER);
+ INSERT INTO t2 VALUES(4), (5);
+ SELECT (SELECT group_concat(a1,'x') FROM t2) FROM t1;
+ }
+} {1x2x3}
+do_test aggnested-1.2 {
+ db eval {
+ SELECT
+ (SELECT group_concat(a1,'x') || '-' || group_concat(b1,'y') FROM t2)
+ FROM t1;
+ }
+} {1x2x3-4y5}
+do_test aggnested-1.3 {
+ db eval {
+ SELECT (SELECT group_concat(b1,a1) FROM t2) FROM t1;
+ }
+} {415 425 435}
+do_test aggnested-1.4 {
+ db eval {
+ SELECT (SELECT group_concat(a1,b1) FROM t2) FROM t1;
+ }
+} {151 252 353}
+
+
+# This test case is a copy of the one in
+# http://www.mail-archive.com/sqlite-users@sqlite.org/msg70787.html
+#
+do_test aggnested-2.0 {
+ sqlite3 db2 :memory:
+ db2 eval {
+ CREATE TABLE t1 (A1 INTEGER NOT NULL,A2 INTEGER NOT NULL,A3 INTEGER NOT
+ NULL,A4 INTEGER NOT NULL,PRIMARY KEY(A1));
+ REPLACE INTO t1 VALUES(1,11,111,1111);
+ REPLACE INTO t1 VALUES(2,22,222,2222);
+ REPLACE INTO t1 VALUES(3,33,333,3333);
+ CREATE TABLE t2 (B1 INTEGER NOT NULL,B2 INTEGER NOT NULL,B3 INTEGER NOT
+ NULL,B4 INTEGER NOT NULL,PRIMARY KEY(B1));
+ REPLACE INTO t2 VALUES(1,88,888,8888);
+ REPLACE INTO t2 VALUES(2,99,999,9999);
+ SELECT (SELECT GROUP_CONCAT(CASE WHEN a1=1 THEN'A' ELSE 'B' END) FROM t2),
+ t1.*
+ FROM t1;
+ }
+} {A,B,B 3 33 333 3333}
+db2 close
+
+finish_test