| 1 |
# 2021 November 16 |
| 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 |
# This file implements regression tests for SQLite library. |
| 12 |
# |
| 13 |
|
| 14 |
set testdir [file dirname $argv0] |
| 15 |
source $testdir/tester.tcl |
| 16 |
set testprefix alterfault |
| 17 |
|
| 18 |
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. |
| 19 |
ifcapable !altertable { |
| 20 |
finish_test |
| 21 |
return |
| 22 |
} |
| 23 |
|
| 24 |
do_execsql_test 1.0 { |
| 25 |
CREATE TABLE t1(a); |
| 26 |
CREATE TEMP TRIGGER tr1 AFTER INSERT ON t1 BEGIN |
| 27 |
SELECT 123; |
| 28 |
END; |
| 29 |
} |
| 30 |
faultsim_save_and_close |
| 31 |
|
| 32 |
do_faultsim_test 1.1 -faults oom* -prep { |
| 33 |
faultsim_restore_and_reopen |
| 34 |
} -body { |
| 35 |
execsql { |
| 36 |
ALTER TABLE t1 ADD COLUMN b CHECK (a!=1) |
| 37 |
} |
| 38 |
} -test { |
| 39 |
faultsim_test_result {0 {}} |
| 40 |
} |
| 41 |
|
| 42 |
reset_db |
| 43 |
do_execsql_test 2.0 { |
| 44 |
CREATE TABLE x1(d, e CONSTRAINT abc NOT NULL, f); |
| 45 |
} |
| 46 |
faultsim_save_and_close |
| 47 |
|
| 48 |
foreach {tn sql} { |
| 49 |
1 { ALTER TABLE x1 ADD CHECK (d!=1) } |
| 50 |
2 { ALTER TABLE x1 ADD CONSTRAINT xyz CHECK (f>d+e); } |
| 51 |
3 { ALTER TABLE x1 DROP CONSTRAINT abc } |
| 52 |
4 { ALTER TABLE x1 ALTER f SET NOT NULL } |
| 53 |
5 { ALTER TABLE x1 ALTER e DROP NOT NULL } |
| 54 |
} { |
| 55 |
do_faultsim_test 2.$tn -faults oom* -prep { |
| 56 |
faultsim_restore_and_reopen |
| 57 |
} -body { |
| 58 |
execsql $::sql |
| 59 |
} -test { |
| 60 |
faultsim_test_result {0 {}} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
# Test an OOM when returning an error. |
| 65 |
# |
| 66 |
do_faultsim_test 2.e -faults oom* -prep { |
| 67 |
faultsim_restore_and_reopen |
| 68 |
} -body { |
| 69 |
execsql { |
| 70 |
ALTER TABLE x1 DROP CONSTRAINT nosuchconstraint |
| 71 |
} |
| 72 |
} -test { |
| 73 |
faultsim_test_result \ |
| 74 |
{1 {no such constraint: nosuchconstraint}} \ |
| 75 |
{1 {SQL logic error}} |
| 76 |
} |
| 77 |
|
| 78 |
finish_test |