blob: 2dc0b46f2938b00f1073866f42b7a73c5024fd92 [file] [log] [blame]
danc2a878e2021-02-17 20:46:44 +00001# 2021 February 18
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 altermalloc3
17
18# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
19ifcapable !altertable {
20 finish_test
21 return
22}
23
danca29bbc2022-05-27 15:33:51 +000024
dan7b57aa32022-02-11 19:41:03 +000025set ::TMPDBERROR [list 1 \
26 {unable to open a temporary database file for storing temporary tables}
27]
28
danc2a878e2021-02-17 20:46:44 +000029do_execsql_test 1.0 {
dan1fffa732021-03-16 18:24:49 +000030 CREATE TABLE x1(
31 one, two, three, PRIMARY KEY(one),
32 CHECK (three!="xyz"), CHECK (two!="one")
33 ) WITHOUT ROWID;
34 CREATE INDEX x1i ON x1(one+"two"+"four") WHERE "five";
35 CREATE TEMP TRIGGER AFTER INSERT ON x1 BEGIN
36 UPDATE x1 SET two=new.three || "new" WHERE one=new.one||"";
37 END;
danc2a878e2021-02-17 20:46:44 +000038 CREATE TABLE t1(a, b, c, d, PRIMARY KEY(d, b)) WITHOUT ROWID;
39 INSERT INTO t1 VALUES(1, 2, 3, 4);
40}
41faultsim_save_and_close
42
43do_faultsim_test 1 -prep {
44 faultsim_restore_and_reopen
45} -body {
46 execsql { ALTER TABLE t1 DROP COLUMN c }
47} -test {
dan7b57aa32022-02-11 19:41:03 +000048 faultsim_test_result {0 {}} $::TMPDBERROR
danc2a878e2021-02-17 20:46:44 +000049}
50
danca29bbc2022-05-27 15:33:51 +000051
dan5a69d192021-09-27 15:44:03 +000052#-------------------------------------------------------------------------
53# dbsqlfuzz e3dd84cda3848016a6a6024c7249d09bc2ef2615
54#
55reset_db
56do_execsql_test 2.0 {
57 CREATE TABLE t2(k,v);
58 CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN
59 UPDATE t2 SET (k,v)= (
60 (WITH cte1(a) AS ( SELECT 1 FROM ( SELECT * FROM t2 ) )
61 SELECT a FROM cte1
62 ), 1);
63 END;
danca29bbc2022-05-27 15:33:51 +000064
65 CREATE TRIGGER r1 AFTER INSERT ON t2 BEGIN
66 UPDATE t2 SET k=1 FROM t2 AS one, t2 AS two NATURAL JOIN t2 AS three
67 WHERE one.k=two.v;
68 END;
dan5a69d192021-09-27 15:44:03 +000069}
70
71faultsim_save_and_close
72faultsim_restore_and_reopen
73
74do_execsql_test 2.1 {
75 ALTER TABLE t2 RENAME TO t2x;
76}
77
78do_faultsim_test 2.2 -prep {
79 faultsim_restore_and_reopen
80 db eval { SELECT * FROM sqlite_master }
81} -body {
82 execsql {
83 ALTER TABLE t2 RENAME TO t2x;
84 }
85} -test {
dan7b57aa32022-02-11 19:41:03 +000086 faultsim_test_result {0 {}} $::TMPDBERROR
dan5a69d192021-09-27 15:44:03 +000087}
danc2a878e2021-02-17 20:46:44 +000088
89finish_test