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