1*4520Snw141292 2*4520Snw141292#pragma ident "%Z%%M% %I% %E% SMI" 3*4520Snw141292 4*4520Snw141292# The author disclaims copyright to this source code. In place of 5*4520Snw141292# a legal notice, here is a blessing: 6*4520Snw141292# 7*4520Snw141292# May you do good and not evil. 8*4520Snw141292# May you find forgiveness for yourself and forgive others. 9*4520Snw141292# May you share freely, never taking more than you give. 10*4520Snw141292# 11*4520Snw141292#*********************************************************************** 12*4520Snw141292# 13*4520Snw141292# This file tests the triggers of views. 14*4520Snw141292# 15*4520Snw141292 16*4520Snw141292set testdir [file dirname $argv0] 17*4520Snw141292source $testdir/tester.tcl 18*4520Snw141292 19*4520Snw141292do_test trigger4-1.1 { 20*4520Snw141292 execsql { 21*4520Snw141292 create table test1(id integer primary key,a); 22*4520Snw141292 create table test2(id integer,b); 23*4520Snw141292 create view test as 24*4520Snw141292 select test1.id as id,a as a,b as b 25*4520Snw141292 from test1 join test2 on test2.id = test1.id; 26*4520Snw141292 create trigger I_test instead of insert on test 27*4520Snw141292 begin 28*4520Snw141292 insert into test1 (id,a) values (NEW.id,NEW.a); 29*4520Snw141292 insert into test2 (id,b) values (NEW.id,NEW.b); 30*4520Snw141292 end; 31*4520Snw141292 insert into test values(1,2,3); 32*4520Snw141292 select * from test1; 33*4520Snw141292 } 34*4520Snw141292} {1 2} 35*4520Snw141292do_test trigger4-1.2 { 36*4520Snw141292 execsql { 37*4520Snw141292 select * from test2; 38*4520Snw141292 } 39*4520Snw141292} {1 3} 40*4520Snw141292do_test trigger4-1.3 { 41*4520Snw141292 db close 42*4520Snw141292 sqlite db test.db 43*4520Snw141292 execsql { 44*4520Snw141292 insert into test values(4,5,6); 45*4520Snw141292 select * from test1; 46*4520Snw141292 } 47*4520Snw141292} {1 2 4 5} 48*4520Snw141292do_test trigger4-1.4 { 49*4520Snw141292 execsql { 50*4520Snw141292 select * from test2; 51*4520Snw141292 } 52*4520Snw141292} {1 3 4 6} 53*4520Snw141292 54*4520Snw141292do_test trigger4-2.1 { 55*4520Snw141292 execsql { 56*4520Snw141292 create trigger U_test instead of update on test 57*4520Snw141292 begin 58*4520Snw141292 update test1 set a=NEW.a where id=NEW.id; 59*4520Snw141292 update test2 set b=NEW.b where id=NEW.id; 60*4520Snw141292 end; 61*4520Snw141292 update test set a=22 where id=1; 62*4520Snw141292 select * from test1; 63*4520Snw141292 } 64*4520Snw141292} {1 22 4 5} 65*4520Snw141292do_test trigger4-2.2 { 66*4520Snw141292 execsql { 67*4520Snw141292 select * from test2; 68*4520Snw141292 } 69*4520Snw141292} {1 3 4 6} 70*4520Snw141292do_test trigger4-2.3 { 71*4520Snw141292 db close 72*4520Snw141292 sqlite db test.db 73*4520Snw141292 execsql { 74*4520Snw141292 update test set b=66 where id=4; 75*4520Snw141292 select * from test1; 76*4520Snw141292 } 77*4520Snw141292} {1 22 4 5} 78*4520Snw141292do_test trigger4-2.4 { 79*4520Snw141292 execsql { 80*4520Snw141292 select * from test2; 81*4520Snw141292 } 82*4520Snw141292} {1 3 4 66} 83*4520Snw141292 84*4520Snw141292do_test trigger4-3.1 { 85*4520Snw141292 catchsql { 86*4520Snw141292 drop table test2; 87*4520Snw141292 insert into test values(7,8,9); 88*4520Snw141292 } 89*4520Snw141292} {1 {no such table: main.test2}} 90*4520Snw141292do_test trigger4-3.2 { 91*4520Snw141292 db close 92*4520Snw141292 sqlite db test.db 93*4520Snw141292 catchsql { 94*4520Snw141292 insert into test values(7,8,9); 95*4520Snw141292 } 96*4520Snw141292} {1 {no such table: main.test2}} 97*4520Snw141292do_test trigger4-3.3 { 98*4520Snw141292 catchsql { 99*4520Snw141292 update test set a=222 where id=1; 100*4520Snw141292 } 101*4520Snw141292} {1 {no such table: main.test2}} 102*4520Snw141292do_test trigger4-3.4 { 103*4520Snw141292 execsql { 104*4520Snw141292 select * from test1; 105*4520Snw141292 } 106*4520Snw141292} {1 22 4 5} 107*4520Snw141292do_test trigger4-3.5 { 108*4520Snw141292 execsql { 109*4520Snw141292 create table test2(id,b); 110*4520Snw141292 insert into test values(7,8,9); 111*4520Snw141292 select * from test1; 112*4520Snw141292 } 113*4520Snw141292} {1 22 4 5 7 8} 114*4520Snw141292do_test trigger4-3.6 { 115*4520Snw141292 execsql { 116*4520Snw141292 select * from test2; 117*4520Snw141292 } 118*4520Snw141292} {7 9} 119*4520Snw141292do_test trigger4-3.7 { 120*4520Snw141292 db close 121*4520Snw141292 sqlite db test.db 122*4520Snw141292 execsql { 123*4520Snw141292 update test set b=99 where id=7; 124*4520Snw141292 select * from test2; 125*4520Snw141292 } 126*4520Snw141292} {7 99} 127*4520Snw141292 128*4520Snw141292integrity_check trigger4-4.1 129*4520Snw141292 130*4520Snw141292finish_test 131