blob: a90be88cf56dddab49316db510323383e830dbab [file] [log] [blame]
danb0137382018-08-20 20:01:01 +00001# 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
dan7b57aa32022-02-11 19:41:03 +000029set ::TMPDBERROR [list 1 \
30 {unable to open a temporary database file for storing temporary tables}
31]
32
33
danb0137382018-08-20 20:01:01 +000034do_faultsim_test 1 -prep {
35 faultsim_restore_and_reopen
36} -body {
37 execsql {
38 ALTER TABLE t1 RENAME abcd TO dcba
39 }
40} -test {
dan7b57aa32022-02-11 19:41:03 +000041 faultsim_test_result {0 {}} $::TMPDBERROR
danb0137382018-08-20 20:01:01 +000042}
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 {
dan7b57aa32022-02-11 19:41:03 +000060 faultsim_test_result {0 {}} $::TMPDBERROR
danb0137382018-08-20 20:01:01 +000061}
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 {
dan7b57aa32022-02-11 19:41:03 +000078 faultsim_test_result {0 {}} $::TMPDBERROR
danb0137382018-08-20 20:01:01 +000079}
dan34566c42018-09-20 17:21:21 +000080
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 {
dan7b57aa32022-02-11 19:41:03 +0000103 faultsim_test_result {0 {}} $::TMPDBERROR
dan34566c42018-09-20 17:21:21 +0000104}
105
dand03d3a92021-06-11 12:14:58 +0000106reset_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 {
dan7b57aa32022-02-11 19:41:03 +0000124 faultsim_test_result {0 {}} $::TMPDBERROR
dand03d3a92021-06-11 12:14:58 +0000125}
126
danb0137382018-08-20 20:01:01 +0000127finish_test