Debian Codegraph @

test/temptrigfault.tes

raw
1 # 2025 November 11
2 #
3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
5 #
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.
9 #
10 #***********************************************************************
11 #
12
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 set testprefix temptrigfault
16
17 forcedelete test.db2
18 do_execsql_test 1.0 {
19 CREATE TABLE t1(x, y);
20 ATTACH 'test.db2' AS aux;
21 CREATE TABLE aux.t1(x, y);
22 }
23
24 do_faultsim_test 1.1 -faults oom* -prep {
25 } -body {
26 execsql {
27 CREATE TEMP TRIGGER tmptrig AFTER INSERT ON t1 BEGIN
28 INSERT INTO aux.t1 VALUES(new.x, new.y);
29 END;
30 }
31 } -test {
32 faultsim_test_result {0 {}}
33 catchsql { DROP TRIGGER tmptrig }
34 }
35
36 do_execsql_test 2.0 {
37 CREATE TEMP TRIGGER tmptrig AFTER INSERT ON t1 BEGIN
38 INSERT INTO aux.t1 VALUES(new.x, new.y);
39 END;
40 }
41
42 do_faultsim_test 2 -faults oom* -prep {
43 } -body {
44 execsql {
45 INSERT INTO t1 VALUES('x', 'y');
46 }
47 } -test {
48 faultsim_test_result {0 {}}
49 }
50
51 do_execsql_test 3.0.1 {
52 SELECT * FROM t1;
53 DELETE FROM t1;
54 DELETE FROM aux.t1;
55 } [db eval {SELECT * FROM aux.t1}]
56
57 do_execsql_test 3.0.2 {
58 CREATE TEMP TRIGGER tmptrig2 AFTER INSERT ON aux.t1 BEGIN
59 INSERT INTO t1 VALUES(new.x||'2', new.y||'2');
60 END;
61 }
62
63 do_faultsim_test 3 -faults oom* -prep {
64 } -body {
65 execsql {
66 INSERT INTO aux.t1 VALUES('aaa', 'bbb');
67 }
68 } -test {
69 faultsim_test_result {0 {}}
70 }
71
72 proc repeatlist {list n} {
73 set ret [list]
74 for {set i 0} {$i < $n} {incr i} {
75 set ret [concat $ret $list]
76 }
77 set ret
78 }
79
80 do_execsql_test 3.x.1 {
81 SELECT * FROM main.t1;
82 } [repeatlist {aaa2 bbb2} 5]
83
84 do_execsql_test 3.x.2 {
85 SELECT * FROM aux.t1;
86 } [repeatlist {aaa bbb aaa2 bbb2} 5]
87
88 faultsim_save_and_close
89 do_faultsim_test 4 -faults oom* -prep {
90 faultsim_restore_and_reopen
91 execsql { ATTACH 'test.db2' AS aux; }
92 } -body {
93 execsql {
94 CREATE TEMP TRIGGER xyz AFTER DELETE ON main.t1 BEGIN
95 DELETE FROM aux.t1 WHERE rowid=old.rowid;
96 END;
97
98 DELETE FROM t1 WHERE rowid=2;
99 }
100 } -test {
101 faultsim_test_result {0 {}} {1 {unable to open a temporary database file for storing temporary tables}}
102 }
103
104 faultsim_save_and_close
105 do_faultsim_test 5 -faults oom* -prep {
106 faultsim_restore_and_reopen
107 execsql { ATTACH 'test.db2' AS aux; }
108 } -body {
109 execsql {
110 CREATE TEMP TRIGGER xyz AFTER UPDATE ON aux.t1 BEGIN
111 UPDATE main.t1 SET x=new.x, y=new.y WHERE rowid=new.rowid;
112 END;
113 UPDATE aux.t1 SET x=x||x WHERE rowid=1+abs(random() % 5);
114 }
115 } -test {
116 faultsim_test_result {0 {}} {1 {unable to open a temporary database file for storing temporary tables}}
117 }
118
119
120 finish_test