AryaWu/sqlite
0
1# 2021 November 162#3# The author disclaims copyright to this source code. In place of4# 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 14set testdir [file dirname $argv0]15source $testdir/tester.tcl16set testprefix alterfault17 18# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.19ifcapable !altertable {20 finish_test21 return22}23 24do_execsql_test 1.0 {25 CREATE TABLE t1(a); 26 CREATE TEMP TRIGGER tr1 AFTER INSERT ON t1 BEGIN27 SELECT 123;28 END;29}30faultsim_save_and_close31 32do_faultsim_test 1.1 -faults oom* -prep {33 faultsim_restore_and_reopen34} -body {35 execsql {36 ALTER TABLE t1 ADD COLUMN b CHECK (a!=1)37 }38} -test {39 faultsim_test_result {0 {}}40}41 42reset_db43do_execsql_test 2.0 {44 CREATE TABLE x1(d, e CONSTRAINT abc NOT NULL, f);45}46faultsim_save_and_close47 48foreach {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_reopen57 } -body {58 execsql $::sql59 } -test {60 faultsim_test_result {0 {}}61 }62}63 64# Test an OOM when returning an error.65#66do_faultsim_test 2.e -faults oom* -prep {67 faultsim_restore_and_reopen68} -body {69 execsql {70 ALTER TABLE x1 DROP CONSTRAINT nosuchconstraint71 }72} -test {73 faultsim_test_result \74 {1 {no such constraint: nosuchconstraint}} \75 {1 {SQL logic error}}76}77 78finish_test79 