1# 2005 January 19 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. The 12# focus of this script is testing correlated subqueries 13# 14# $Id: subquery.test,v 1.2 2005/01/21 11:55:28 danielk1977 Exp $ 15# 16 17set testdir [file dirname $argv0] 18source $testdir/tester.tcl 19 20ifcapable !subquery { 21 finish_test 22 return 23} 24 25do_test subquery-1.1 { 26 execsql { 27 BEGIN; 28 CREATE TABLE t1(a,b); 29 INSERT INTO t1 VALUES(1,2); 30 INSERT INTO t1 VALUES(3,4); 31 INSERT INTO t1 VALUES(5,6); 32 INSERT INTO t1 VALUES(7,8); 33 CREATE TABLE t2(x,y); 34 INSERT INTO t2 VALUES(1,1); 35 INSERT INTO t2 VALUES(3,9); 36 INSERT INTO t2 VALUES(5,25); 37 INSERT INTO t2 VALUES(7,49); 38 COMMIT; 39 } 40 execsql { 41 SELECT a, (SELECT y FROM t2 WHERE x=a) FROM t1 WHERE b<8 42 } 43} {1 1 3 9 5 25} 44do_test subquery-1.2 { 45 execsql { 46 UPDATE t1 SET b=b+(SELECT y FROM t2 WHERE x=a); 47 SELECT * FROM t1; 48 } 49} {1 3 3 13 5 31 7 57} 50 51do_test subquery-1.3 { 52 execsql { 53 SELECT b FROM t1 WHERE EXISTS(SELECT * FROM t2 WHERE y=a) 54 } 55} {3} 56do_test subquery-1.4 { 57 execsql { 58 SELECT b FROM t1 WHERE NOT EXISTS(SELECT * FROM t2 WHERE y=a) 59 } 60} {13 31 57} 61 62 63finish_test 64