xref: /sqlite-3.40.0/test/altermalloc2.test (revision 8c53b4e7)
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
29do_faultsim_test 1 -prep {
30  faultsim_restore_and_reopen
31} -body {
32  execsql {
33    ALTER TABLE t1 RENAME abcd TO dcba
34  }
35} -test {
36  faultsim_test_result {0 {}}
37}
38
39catch {db close}
40forcedelete test.db
41sqlite3 db test.db
42do_execsql_test 2.0 {
43  PRAGMA encoding = 'utf-16';
44  CREATE TABLE t1(abcd, efgh);
45}
46faultsim_save_and_close
47
48do_faultsim_test 2 -prep {
49  faultsim_restore_and_reopen
50} -body {
51  execsql {
52    ALTER TABLE t1 RENAME abcd TO dcba
53  }
54} -test {
55  faultsim_test_result {0 {}}
56}
57
58
59reset_db
60do_execsql_test 3.0 {
61  CREATE TABLE t1(abcd, efgh);
62  CREATE VIEW v1 AS SELECT * FROM t1 WHERE abcd>efgh;
63}
64faultsim_save_and_close
65
66do_faultsim_test 3 -prep {
67  faultsim_restore_and_reopen
68} -body {
69  execsql {
70    ALTER TABLE t1 RENAME abcd TO dcba
71  }
72} -test {
73  faultsim_test_result {0 {}}
74}
75
76reset_db
77do_execsql_test 4.0 {
78  CREATE TABLE rr(a, b);
79  CREATE VIEW vv AS SELECT * FROM rr;
80
81  CREATE TRIGGER vv1 INSTEAD OF INSERT ON vv BEGIN
82    SELECT 1, 2, 3;
83  END;
84  CREATE TRIGGER tr1 AFTER INSERT ON rr BEGIN
85    INSERT INTO vv VALUES(new.a, new.b);
86  END;
87} {}
88
89faultsim_save_and_close
90do_faultsim_test 4 -faults oom-* -prep {
91  faultsim_restore_and_reopen
92  execsql { SELECT * FROM sqlite_master }
93} -body {
94  execsql {
95    ALTER TABLE rr RENAME a TO c;
96  }
97} -test {
98  faultsim_test_result {0 {}}
99}
100
101finish_test
102