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 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing that a trigger may have the same
13 # name as an index, view or table in the same database.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 #--------------------------------------------------------------------------
22 # schema4-1.*: Dropping and creating triggers and other objects where
23 # triggers and at least on other object share a name.
25 # schema4-2.*: Renaming tables where there is a trigger that shares the
26 # name of the table or one of its indices.
29 do_execsql_test schema4-1.1 {
30 CREATE TABLE log(x, a, b);
31 CREATE TABLE tbl(a, b);
33 CREATE TABLE t1(a, b);
34 CREATE VIEW v1 AS SELECT * FROM tbl;
35 CREATE INDEX i1 ON tbl(a);
38 do_execsql_test schema4-1.2 {
39 CREATE TRIGGER t1 AFTER INSERT ON tbl BEGIN
40 INSERT INTO log VALUES('after insert', new.a, new.b);
42 CREATE TRIGGER v1 AFTER UPDATE ON tbl BEGIN
43 INSERT INTO log VALUES('after update', new.a, new.b);
45 CREATE TRIGGER i1 AFTER DELETE ON tbl BEGIN
46 INSERT INTO log VALUES('after delete', old.a, old.b);
50 do_execsql_test schema4-1.3 {
51 INSERT INTO tbl VALUES(1, 2);
52 UPDATE tbl SET b=a+b, a=a+1;
55 SELECT x, a, b FROM log;
56 } {{after insert} 1 2 {after update} 2 3 {after delete} 2 3}
58 do_execsql_test schema4-1.4 {
65 INSERT INTO tbl VALUES(1, 2);
66 UPDATE tbl SET b=a+b, a=a+1;
69 SELECT x, a, b FROM log;
70 } {{after insert} 1 2 {after update} 2 3 {after delete} 2 3}
75 do_execsql_test schema4-1.5 {
77 INSERT INTO tbl VALUES(1, 2);
78 UPDATE tbl SET b=a+b, a=a+1;
80 SELECT x, a, b FROM log;
81 } {{after insert} 1 2 {after update} 2 3 {after delete} 2 3}
83 do_execsql_test schema4-1.6 {
84 CREATE TABLE t1(a, b);
85 CREATE VIEW v1 AS SELECT * FROM tbl;
86 CREATE INDEX i1 ON tbl(a);
90 do_execsql_test schema4-1.7 {
92 CREATE VIRTUAL TABLE t1 USING fts3;
95 do_execsql_test schema4-1.8 {
98 INSERT INTO tbl VALUES(1, 2);
99 UPDATE tbl SET b=a+b, a=a+1;
101 SELECT x, a, b FROM log;
102 } {{after insert} 1 2 {after update} 2 3 {after delete} 2 3}
105 ifcapable altertable {
107 do_execsql_test schema4-2.1 {
108 CREATE TABLE log(x, a, b);
109 CREATE TABLE tbl(a, b);
111 CREATE TABLE t1(a, b);
112 CREATE INDEX i1 ON t1(a, b);
115 do_execsql_test schema4-2.2 {
116 CREATE TRIGGER t1 AFTER INSERT ON tbl BEGIN
117 INSERT INTO log VALUES('after insert', new.a, new.b);
119 CREATE TRIGGER i1 AFTER DELETE ON tbl BEGIN
120 INSERT INTO log VALUES('after delete', old.a, old.b);
124 do_execsql_test schema4-2.3 { ALTER TABLE t1 RENAME TO t2 } {}
126 do_execsql_test schema4-2.4 {
127 INSERT INTO tbl VALUES('a', 'b');
130 } {{after insert} a b {after delete} a b}
135 do_execsql_test schema4-2.5 {
137 INSERT INTO tbl VALUES('c', 'd');
140 } {{after insert} c d {after delete} c d}
142 do_execsql_test schema4-2.6 {
143 CREATE TEMP TRIGGER x1 AFTER UPDATE ON tbl BEGIN
144 INSERT INTO log VALUES('after update', new.a, new.b);
147 CREATE TEMP TABLE x1(x);
148 INSERT INTO x1 VALUES(123);
151 do_execsql_test schema4-2.8 {
152 select sql from sqlite_temp_master WHERE type='table';
153 } {{CREATE TABLE x1(x)}}
155 do_execsql_test schema4-2.7 { ALTER TABLE tbl RENAME TO tbl2 } {}
157 do_execsql_test schema4-2.9 {
158 select sql from sqlite_temp_master WHERE type='table';
159 } {{CREATE TABLE x1(x)}}
161 do_execsql_test schema4-2.10 {
163 INSERT INTO tbl2 VALUES('e', 'f');
164 UPDATE tbl2 SET a='g', b='h';
167 } {{after insert} e f {after update} g h {after delete} g h}
169 do_execsql_test schema4-2.11 {
170 INSERT INTO x1 VALUES(456);