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.
13 # This file implements tests to increase coverage of trigger.c.
15 # $Id: trigger7.test,v 1.3 2008/08/11 18:44:58 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 ifcapable {!trigger} {
24 # Error messages resulting from qualified trigger names.
26 do_test trigger7-1.1 {
28 CREATE TABLE t1(x, y);
31 CREATE TEMP TRIGGER main.r1 AFTER INSERT ON t1 BEGIN
35 } {1 {temporary trigger may not have qualified name}}
36 do_test trigger7-1.2 {
38 CREATE TRIGGER not_a_db.r1 AFTER INSERT ON t1 BEGIN
42 } {1 {unknown database not_a_db}}
45 # When the UPDATE OF syntax is used, no code is generated for triggers
46 # that do not match the update columns.
49 do_test trigger7-2.1 {
51 CREATE TRIGGER r1 AFTER UPDATE OF x ON t1 BEGIN
52 SELECT '___update_t1.x___';
54 CREATE TRIGGER r2 AFTER UPDATE OF y ON t1 BEGIN
55 SELECT '___update_t1.y___';
58 set txt [db eval {EXPLAIN UPDATE t1 SET x=5}]
59 string match *___update_t1.x___* $txt
61 do_test trigger7-2.2 {
62 set txt [db eval {EXPLAIN UPDATE t1 SET x=5}]
63 string match *___update_t1.y___* $txt
65 do_test trigger7-2.3 {
66 set txt [db eval {EXPLAIN UPDATE t1 SET y=5}]
67 string match *___update_t1.x___* $txt
69 do_test trigger7-2.4 {
70 set txt [db eval {EXPLAIN UPDATE t1 SET y=5}]
71 string match *___update_t1.y___* $txt
73 do_test trigger7-2.5 {
74 set txt [db eval {EXPLAIN UPDATE t1 SET rowid=5}]
75 string match *___update_t1.x___* $txt
77 do_test trigger7-2.6 {
78 set txt [db eval {EXPLAIN UPDATE t1 SET rowid=5}]
79 string match *___update_t1.x___* $txt
83 # Test the ability to create many triggers on the same table, then
84 # selectively drop those triggers.
86 do_test trigger7-3.1 {
88 CREATE TABLE t2(x,y,z);
89 CREATE TRIGGER t2r1 AFTER INSERT ON t2 BEGIN SELECT 1; END;
90 CREATE TRIGGER t2r2 BEFORE INSERT ON t2 BEGIN SELECT 1; END;
91 CREATE TRIGGER t2r3 AFTER UPDATE ON t2 BEGIN SELECT 1; END;
92 CREATE TRIGGER t2r4 BEFORE UPDATE ON t2 BEGIN SELECT 1; END;
93 CREATE TRIGGER t2r5 AFTER DELETE ON t2 BEGIN SELECT 1; END;
94 CREATE TRIGGER t2r6 BEFORE DELETE ON t2 BEGIN SELECT 1; END;
95 CREATE TRIGGER t2r7 AFTER INSERT ON t2 BEGIN SELECT 1; END;
96 CREATE TRIGGER t2r8 BEFORE INSERT ON t2 BEGIN SELECT 1; END;
97 CREATE TRIGGER t2r9 AFTER UPDATE ON t2 BEGIN SELECT 1; END;
98 CREATE TRIGGER t2r10 BEFORE UPDATE ON t2 BEGIN SELECT 1; END;
99 CREATE TRIGGER t2r11 AFTER DELETE ON t2 BEGIN SELECT 1; END;
100 CREATE TRIGGER t2r12 BEFORE DELETE ON t2 BEGIN SELECT 1; END;
105 # This test corrupts the database file so it must be the last test
108 do_test trigger7-99.1 {
109 sqlite3_db_config db DEFENSIVE 0
111 PRAGMA writable_schema=on;
112 UPDATE sqlite_master SET sql='nonsense';
115 catch { sqlite3 db test.db }
116 catchsql { DROP TRIGGER t2r5 }
117 } {/1 {malformed database schema .*}/}