1# 2018 August 20 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 13set testdir [file dirname $argv0] 14source $testdir/tester.tcl 15source $testdir/malloc_common.tcl 16set testprefix altermalloc2 17 18# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. 19ifcapable !altertable { 20 finish_test 21 return 22} 23 24do_execsql_test 1.0 { 25 CREATE TABLE t1(abcd, efgh); 26} 27faultsim_save_and_close 28 29set ::TMPDBERROR [list 1 \ 30 {unable to open a temporary database file for storing temporary tables} 31] 32 33 34do_faultsim_test 1 -prep { 35 faultsim_restore_and_reopen 36} -body { 37 execsql { 38 ALTER TABLE t1 RENAME abcd TO dcba 39 } 40} -test { 41 faultsim_test_result {0 {}} $::TMPDBERROR 42} 43 44catch {db close} 45forcedelete test.db 46sqlite3 db test.db 47do_execsql_test 2.0 { 48 PRAGMA encoding = 'utf-16'; 49 CREATE TABLE t1(abcd, efgh); 50} 51faultsim_save_and_close 52 53do_faultsim_test 2 -prep { 54 faultsim_restore_and_reopen 55} -body { 56 execsql { 57 ALTER TABLE t1 RENAME abcd TO dcba 58 } 59} -test { 60 faultsim_test_result {0 {}} $::TMPDBERROR 61} 62 63 64reset_db 65do_execsql_test 3.0 { 66 CREATE TABLE t1(abcd, efgh); 67 CREATE VIEW v1 AS SELECT * FROM t1 WHERE abcd>efgh; 68} 69faultsim_save_and_close 70 71do_faultsim_test 3 -prep { 72 faultsim_restore_and_reopen 73} -body { 74 execsql { 75 ALTER TABLE t1 RENAME abcd TO dcba 76 } 77} -test { 78 faultsim_test_result {0 {}} $::TMPDBERROR 79} 80 81reset_db 82do_execsql_test 4.0 { 83 CREATE TABLE rr(a, b); 84 CREATE VIEW vv AS SELECT * FROM rr; 85 86 CREATE TRIGGER vv1 INSTEAD OF INSERT ON vv BEGIN 87 SELECT 1, 2, 3; 88 END; 89 CREATE TRIGGER tr1 AFTER INSERT ON rr BEGIN 90 INSERT INTO vv VALUES(new.a, new.b); 91 END; 92} {} 93 94faultsim_save_and_close 95do_faultsim_test 4 -faults oom-* -prep { 96 faultsim_restore_and_reopen 97 execsql { SELECT * FROM sqlite_master } 98} -body { 99 execsql { 100 ALTER TABLE rr RENAME a TO c; 101 } 102} -test { 103 faultsim_test_result {0 {}} $::TMPDBERROR 104} 105 106reset_db 107do_execsql_test 5.0 { 108 CREATE TABLE rr(a, b); 109 CREATE VIEW vv AS SELECT * FROM ( 110 WITH abc(d, e) AS (SELECT * FROM rr) 111 SELECT * FROM abc 112 ); 113} {} 114 115faultsim_save_and_close 116do_faultsim_test 5 -faults oom-* -prep { 117 faultsim_restore_and_reopen 118 execsql { SELECT * FROM sqlite_master } 119} -body { 120 execsql { 121 ALTER TABLE rr RENAME TO c; 122 } 123} -test { 124 faultsim_test_result {0 {}} $::TMPDBERROR 125} 126 127finish_test 128