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} {
25 # Error messages resulting from qualified trigger names.
27 do_test trigger7-1.1 {
29 CREATE TABLE t1(x, y);
32 CREATE TEMP TRIGGER main.r1 AFTER INSERT ON t1 BEGIN
36 } {1 {temporary trigger may not have qualified name}}
37 do_test trigger7-1.2 {
39 CREATE TRIGGER not_a_db.r1 AFTER INSERT ON t1 BEGIN
43 } {1 {unknown database not_a_db}}
46 # When the UPDATE OF syntax is used, no code is generated for triggers
47 # that do not match the update columns.
50 do_test trigger7-2.1 {
52 CREATE TRIGGER r1 AFTER UPDATE OF x ON t1 BEGIN
53 SELECT '___update_t1.x___';
55 CREATE TRIGGER r2 AFTER UPDATE OF y ON t1 BEGIN
56 SELECT '___update_t1.y___';
59 set txt [db eval {EXPLAIN UPDATE t1 SET x=5}]
60 string match *___update_t1.x___* $txt
62 do_test trigger7-2.2 {
63 set txt [db eval {EXPLAIN UPDATE t1 SET x=5}]
64 string match *___update_t1.y___* $txt
66 do_test trigger7-2.3 {
67 set txt [db eval {EXPLAIN UPDATE t1 SET y=5}]
68 string match *___update_t1.x___* $txt
70 do_test trigger7-2.4 {
71 set txt [db eval {EXPLAIN UPDATE t1 SET y=5}]
72 string match *___update_t1.y___* $txt
74 do_test trigger7-2.5 {
75 set txt [db eval {EXPLAIN UPDATE t1 SET rowid=5}]
76 string match *___update_t1.x___* $txt
78 do_test trigger7-2.6 {
79 set txt [db eval {EXPLAIN UPDATE t1 SET rowid=5}]
80 string match *___update_t1.x___* $txt
84 # Test the ability to create many triggers on the same table, then
85 # selectively drop those triggers.
87 do_test trigger7-3.1 {
89 CREATE TABLE t2(x,y,z);
90 CREATE TRIGGER t2r1 AFTER INSERT ON t2 BEGIN SELECT 1; END;
91 CREATE TRIGGER t2r2 BEFORE INSERT ON t2 BEGIN SELECT 1; END;
92 CREATE TRIGGER t2r3 AFTER UPDATE ON t2 BEGIN SELECT 1; END;
93 CREATE TRIGGER t2r4 BEFORE UPDATE ON t2 BEGIN SELECT 1; END;
94 CREATE TRIGGER t2r5 AFTER DELETE ON t2 BEGIN SELECT 1; END;
95 CREATE TRIGGER t2r6 BEFORE DELETE ON t2 BEGIN SELECT 1; END;
96 CREATE TRIGGER t2r7 AFTER INSERT ON t2 BEGIN SELECT 1; END;
97 CREATE TRIGGER t2r8 BEFORE INSERT ON t2 BEGIN SELECT 1; END;
98 CREATE TRIGGER t2r9 AFTER UPDATE ON t2 BEGIN SELECT 1; END;
99 CREATE TRIGGER t2r10 BEFORE UPDATE ON t2 BEGIN SELECT 1; END;
100 CREATE TRIGGER t2r11 AFTER DELETE ON t2 BEGIN SELECT 1; END;
101 CREATE TRIGGER t2r12 BEFORE DELETE ON t2 BEGIN SELECT 1; END;
106 # This test corrupts the database file so it must be the last test
109 do_test trigger7-99.1 {
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 (t2r12) - near "nonsense": syntax error}}