AryaWu/sqlite
0
1# 2025 November 112#3# The author disclaims copyright to this source code. In place of4# 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 13set testdir [file dirname $argv0]14source $testdir/tester.tcl15set testprefix temptrigfault16 17forcedelete test.db218do_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 24do_faultsim_test 1.1 -faults oom* -prep {25} -body {26 execsql {27 CREATE TEMP TRIGGER tmptrig AFTER INSERT ON t1 BEGIN28 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 36do_execsql_test 2.0 {37 CREATE TEMP TRIGGER tmptrig AFTER INSERT ON t1 BEGIN38 INSERT INTO aux.t1 VALUES(new.x, new.y);39 END;40}41 42do_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 51do_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 57do_execsql_test 3.0.2 {58 CREATE TEMP TRIGGER tmptrig2 AFTER INSERT ON aux.t1 BEGIN59 INSERT INTO t1 VALUES(new.x||'2', new.y||'2');60 END;61}62 63do_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 72proc 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 ret78}79 80do_execsql_test 3.x.1 {81 SELECT * FROM main.t1;82} [repeatlist {aaa2 bbb2} 5]83 84do_execsql_test 3.x.2 {85 SELECT * FROM aux.t1;86} [repeatlist {aaa bbb aaa2 bbb2} 5]87 88faultsim_save_and_close89do_faultsim_test 4 -faults oom* -prep {90 faultsim_restore_and_reopen91 execsql { ATTACH 'test.db2' AS aux; }92} -body {93 execsql {94 CREATE TEMP TRIGGER xyz AFTER DELETE ON main.t1 BEGIN95 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 104faultsim_save_and_close105do_faultsim_test 5 -faults oom* -prep {106 faultsim_restore_and_reopen107 execsql { ATTACH 'test.db2' AS aux; }108} -body {109 execsql {110 CREATE TEMP TRIGGER xyz AFTER UPDATE ON aux.t1 BEGIN111 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 120finish_test121 