3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #*************************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 set testprefix altertrig
17 # If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
18 ifcapable !altertable {
23 proc collapse_whitespace {in} {
24 regsub -all {[ \t\n]+} [string trim $in] { }
27 proc do_whitespace_sql_test {tn sql res} {
28 set got [execsql $sql]
31 foreach g $got { lappend wgot [collapse_whitespace $g] }
32 foreach r $res { lappend wres [collapse_whitespace $r] }
34 uplevel [list do_test $tn [list set {} $wgot] $wres]
43 CREATE TRIGGER r1 INSERT ON t1 BEGIN
44 UPDATE t1 SET d='xyz' FROM t2, t3;
48 do_whitespace_sql_test 1.1 {
49 ALTER TABLE t3 RENAME TO t5;
50 SELECT sql FROM sqlite_schema WHERE type='trigger';
52 CREATE TRIGGER r1 INSERT ON t1 BEGIN
53 UPDATE t1 SET d='xyz' FROM t2, "t5";
59 CREATE TRIGGER r1 INSERT ON t1 BEGIN
60 UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM t5);
64 do_whitespace_sql_test 1.3 {
65 ALTER TABLE t5 RENAME TO t3;
66 SELECT sql FROM sqlite_schema WHERE type='trigger';
68 CREATE TRIGGER r1 INSERT ON t1 BEGIN
69 UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM "t3");
73 foreach {tn alter update final} {
75 ALTER TABLE t3 RENAME TO t10
77 UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM t3)
79 UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM "t10")
83 ALTER TABLE t3 RENAME TO t10
85 UPDATE t1 SET a='xyz' FROM t3, (SELECT * FROM (SELECT e FROM t3))
87 UPDATE t1 SET a='xyz' FROM "t10", (SELECT * FROM (SELECT e FROM "t10"))
91 ALTER TABLE t3 RENAME e TO abc
93 UPDATE t1 SET a='xyz' FROM t3, (SELECT * FROM (SELECT e FROM t3))
95 UPDATE t1 SET a='xyz' FROM t3, (SELECT * FROM (SELECT abc FROM t3))
99 ALTER TABLE t2 RENAME c TO abc
101 UPDATE t1 SET a='xyz' FROM t3, (SELECT 1 FROM t2 WHERE c)
103 UPDATE t1 SET a='xyz' FROM t3, (SELECT 1 FROM t2 WHERE abc)
107 ALTER TABLE t2 RENAME c TO abc
109 UPDATE t1 SET a=t2.c FROM t2
111 UPDATE t1 SET a=t2.abc FROM t2
115 ALTER TABLE t2 RENAME c TO abc
117 UPDATE t1 SET a=t2.c FROM t2, t3
119 UPDATE t1 SET a=t2.abc FROM t2, t3
123 ALTER TABLE t4 RENAME e TO abc
125 UPDATE t1 SET a=1 FROM t3 NATURAL JOIN t4 WHERE t4.e=a
127 UPDATE t1 SET a=1 FROM t3 NATURAL JOIN t4 WHERE t4.abc=a
131 ALTER TABLE t4 RENAME TO abc
133 UPDATE t1 SET a=1 FROM t3 NATURAL JOIN t4 WHERE t4.e=a
135 UPDATE t1 SET a=1 FROM t3 NATURAL JOIN "abc" WHERE "abc".e=a
140 do_execsql_test 2.$tn.1 {
141 CREATE TABLE t1(a,b);
142 CREATE TABLE t2(c,d);
143 CREATE TABLE t3(e,f);
144 CREATE TABLE t4(e,f);
146 do_execsql_test 2.$tn.2 "
147 CREATE TRIGGER r1 INSERT ON t1 BEGIN
151 do_execsql_test 2.$tn.3 $alter
153 do_whitespace_sql_test 2.$tn.4 {
154 SELECT sqL FROM sqlite_schema WHERE type='trigger'
156 CREATE TRIGGER r1 INSERT ON t1 BEGIN