1 # 2008 August 12 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 # 12 # This file tests changes to the name resolution logic that occurred 13 # in august of 2008 and where associated with tickets #3298 and #3301 14 # 15 # $Id: tkt3298.test,v 1.3 2009/04/07 14:14:23 danielk1977 Exp $ 16 17 set testdir [file dirname $argv0] 18 source $testdir/tester.tcl 19 20 ifcapable !trigger { finish_test ; return } 21 22 do_test tkt3298-1.1 { 23 execsql { 24 CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT); 25 INSERT INTO t1 VALUES(0, 1); 26 INSERT INTO t1 VALUES(1, 1); 27 INSERT INTO t1 VALUES(2, 1); 28 CREATE VIEW v1 AS SELECT a AS x, b+1 AS y FROM t1; 29 CREATE TRIGGER r1 INSTEAD OF UPDATE ON v1 30 BEGIN 31 UPDATE t1 SET b=new.y-1 WHERE a=new.x; 32 END; 33 CREATE TRIGGER r2 INSTEAD OF DELETE ON v1 34 BEGIN 35 DELETE FROM t1 WHERE a=old.x; 36 END; 37 SELECT * FROM v1 ORDER BY x; 38 } 39 } {0 2 1 2 2 2} 40 do_test tkt3298-1.2 { 41 execsql { 42 UPDATE v1 SET y=3 WHERE x=0; 43 SELECT * FROM v1 ORDER by x; 44 } 45 } {0 3 1 2 2 2} 46 do_test tkt3298-1.3 { 47 execsql { 48 UPDATE v1 SET y=4 WHERE v1.x=2; 49 SELECT * FROM v1 ORDER by x; 50 } 51 } {0 3 1 2 2 4} 52 do_test tkt3298-1.4 { 53 execsql { 54 DELETE FROM v1 WHERE x=1; 55 SELECT * FROM v1 ORDER BY x; 56 } 57 } {0 3 2 4} 58 do_test tkt3298-1.5 { 59 execsql { 60 DELETE FROM v1 WHERE v1.x=2; 61 SELECT * FROM v1 ORDER BY x; 62 } 63 } {0 3} 64 65 # Ticket #3301 66 # 67 do_test tkt3298-2.1 { 68 execsql { 69 CREATE TABLE t2(p,q); 70 INSERT INTO t2 VALUES(1,11); 71 INSERT INTO t2 VALUES(2,22); 72 CREATE TABLE t3(x,y); 73 INSERT INTO t3 VALUES(1,'one'); 74 75 SELECT *, (SELECT z FROM (SELECT y AS z FROM t3 WHERE x=t1.a+1) ) FROM t1; 76 } 77 } {0 2 one} 78 79 80 finish_test 81