Snapshot of upstream SQLite 3.37.2
[sqlcipher.git] / test / altermalloc3.test
blob4c10f48fed5f8ce67c37d0197ea33b362c2843dd
1 # 2021 February 18
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #*************************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 source $testdir/malloc_common.tcl
16 set testprefix altermalloc3
18 # If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
19 ifcapable !altertable {
20   finish_test
21   return
24 do_execsql_test 1.0 {
25   CREATE TABLE x1(
26       one, two, three, PRIMARY KEY(one), 
27       CHECK (three!="xyz"), CHECK (two!="one")
28   ) WITHOUT ROWID;
29   CREATE INDEX x1i ON x1(one+"two"+"four") WHERE "five";
30   CREATE TEMP TRIGGER AFTER INSERT ON x1 BEGIN
31     UPDATE x1 SET two=new.three || "new" WHERE one=new.one||"";
32   END;
33   CREATE TABLE t1(a, b, c, d, PRIMARY KEY(d, b)) WITHOUT ROWID;
34   INSERT INTO t1 VALUES(1, 2, 3, 4);
36 faultsim_save_and_close
38 do_faultsim_test 1 -prep {
39   faultsim_restore_and_reopen
40 } -body {
41   execsql { ALTER TABLE t1 DROP COLUMN c }
42 } -test {
43   faultsim_test_result {0 {}}
46 #-------------------------------------------------------------------------
47 # dbsqlfuzz e3dd84cda3848016a6a6024c7249d09bc2ef2615
49 reset_db
50 do_execsql_test 2.0 {
51   CREATE TABLE t2(k,v);
52   CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN
53     UPDATE t2 SET (k,v)= (
54        (WITH cte1(a) AS ( SELECT 1 FROM ( SELECT * FROM t2 ) )
55        SELECT a FROM cte1
56     ), 1);
57   END;
60 faultsim_save_and_close
61 faultsim_restore_and_reopen
63 do_execsql_test 2.1 {
64   ALTER TABLE t2 RENAME TO t2x;
67 do_faultsim_test 2.2 -prep {
68   faultsim_restore_and_reopen
69   db eval { SELECT * FROM sqlite_master } 
70 } -body {
71   execsql {
72     ALTER TABLE t2 RENAME TO t2x;
73   }
74 } -test {
75   faultsim_test_result {0 {}}
78 finish_test