sl@0: # 2005 September 19 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #************************************************************************* sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus of this script is testing the ALTER TABLE statement and sl@0: # specifically out-of-memory conditions within that command. sl@0: # sl@0: # $Id: altermalloc.test,v 1.9 2008/08/04 20:13:27 drh Exp $ sl@0: # sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # If SQLITE_OMIT_ALTERTABLE is defined, omit this file. sl@0: ifcapable !altertable||!memdebug { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: source $testdir/malloc_common.tcl sl@0: sl@0: do_malloc_test altermalloc-1 -tclprep { sl@0: db close sl@0: } -tclbody { sl@0: if {[catch {sqlite3 db test.db}]} { sl@0: error "out of memory" sl@0: } sl@0: sqlite3_db_config_lookaside db 0 0 0 sl@0: sqlite3_extended_result_codes db 1 sl@0: } -sqlbody { sl@0: CREATE TABLE t1(a int); sl@0: ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL; sl@0: ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text'; sl@0: ALTER TABLE t1 RENAME TO t2; sl@0: } sl@0: sl@0: # Test malloc() failure on an ALTER TABLE on a virtual table. sl@0: # sl@0: ifcapable vtab { sl@0: do_malloc_test altermalloc-vtab -tclprep { sl@0: sqlite3 db2 test.db sl@0: sqlite3_db_config_lookaside db2 0 0 0 sl@0: sqlite3_extended_result_codes db2 1 sl@0: register_echo_module [sqlite3_connection_pointer db2] sl@0: db2 eval { sl@0: CREATE TABLE t1(a, b VARCHAR, c INTEGER); sl@0: CREATE VIRTUAL TABLE t1echo USING echo(t1); sl@0: } sl@0: db2 close sl@0: sl@0: register_echo_module [sqlite3_connection_pointer db] sl@0: } -tclbody { sl@0: set rc [catch {db eval { ALTER TABLE t1echo RENAME TO t1_echo }} msg] sl@0: if {$msg eq "vtable constructor failed: t1echo"} { sl@0: set msg "out of memory" sl@0: } sl@0: if {$rc} { sl@0: error $msg sl@0: } sl@0: } sl@0: } sl@0: sl@0: finish_test