xref: /sqlite-3.40.0/test/altermalloc3.test (revision dedd51ae)
1# 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
24set ::TMPDBERROR [list 1 \
25  {unable to open a temporary database file for storing temporary tables}
26]
27
28do_execsql_test 1.0 {
29  CREATE TABLE x1(
30      one, two, three, PRIMARY KEY(one),
31      CHECK (three!="xyz"), CHECK (two!="one")
32  ) WITHOUT ROWID;
33  CREATE INDEX x1i ON x1(one+"two"+"four") WHERE "five";
34  CREATE TEMP TRIGGER AFTER INSERT ON x1 BEGIN
35    UPDATE x1 SET two=new.three || "new" WHERE one=new.one||"";
36  END;
37  CREATE TABLE t1(a, b, c, d, PRIMARY KEY(d, b)) WITHOUT ROWID;
38  INSERT INTO t1 VALUES(1, 2, 3, 4);
39}
40faultsim_save_and_close
41
42do_faultsim_test 1 -prep {
43  faultsim_restore_and_reopen
44} -body {
45  execsql { ALTER TABLE t1 DROP COLUMN c }
46} -test {
47  faultsim_test_result {0 {}} $::TMPDBERROR
48}
49
50#-------------------------------------------------------------------------
51# dbsqlfuzz e3dd84cda3848016a6a6024c7249d09bc2ef2615
52#
53reset_db
54do_execsql_test 2.0 {
55  CREATE TABLE t2(k,v);
56  CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN
57    UPDATE t2 SET (k,v)= (
58       (WITH cte1(a) AS ( SELECT 1 FROM ( SELECT * FROM t2 ) )
59       SELECT a FROM cte1
60    ), 1);
61  END;
62}
63
64faultsim_save_and_close
65faultsim_restore_and_reopen
66
67do_execsql_test 2.1 {
68  ALTER TABLE t2 RENAME TO t2x;
69}
70
71do_faultsim_test 2.2 -prep {
72  faultsim_restore_and_reopen
73  db eval { SELECT * FROM sqlite_master }
74} -body {
75  execsql {
76    ALTER TABLE t2 RENAME TO t2x;
77  }
78} -test {
79  faultsim_test_result {0 {}} $::TMPDBERROR
80}
81
82finish_test
83