blob: be08d0e12da7a4915423395e43eab14160e4a8db [file] [log] [blame]
drh0bbaa1b2005-08-19 19:14:12 +00001# 2005 September 19
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. The
12# focus of this script is testing the ALTER TABLE statement and
13# specifically out-of-memory conditions within that command.
14#
drhe9d1c722008-08-04 20:13:26 +000015# $Id: altermalloc.test,v 1.9 2008/08/04 20:13:27 drh Exp $
drh0bbaa1b2005-08-19 19:14:12 +000016#
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
drh0bbaa1b2005-08-19 19:14:12 +000021# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
drhda578952007-08-27 23:48:23 +000022ifcapable !altertable||!memdebug {
drh0bbaa1b2005-08-19 19:14:12 +000023 finish_test
24 return
25}
26
danielk1977cdc3a6b2007-08-25 13:09:26 +000027source $testdir/malloc_common.tcl
drh0bbaa1b2005-08-19 19:14:12 +000028
29do_malloc_test altermalloc-1 -tclprep {
30 db close
31} -tclbody {
32 if {[catch {sqlite3 db test.db}]} {
33 error "out of memory"
34 }
drhe9d1c722008-08-04 20:13:26 +000035 sqlite3_db_config_lookaside db 0 0 0
danielk1977ae72d982007-10-03 08:46:44 +000036 sqlite3_extended_result_codes db 1
drh0bbaa1b2005-08-19 19:14:12 +000037} -sqlbody {
38 CREATE TABLE t1(a int);
39 ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL;
40 ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text';
41 ALTER TABLE t1 RENAME TO t2;
42}
43
danielk1977880c15b2007-09-01 18:24:55 +000044# Test malloc() failure on an ALTER TABLE on a virtual table.
45#
46ifcapable vtab {
47 do_malloc_test altermalloc-vtab -tclprep {
48 sqlite3 db2 test.db
drhe9d1c722008-08-04 20:13:26 +000049 sqlite3_db_config_lookaside db2 0 0 0
danielk1977ae72d982007-10-03 08:46:44 +000050 sqlite3_extended_result_codes db2 1
danielk1977880c15b2007-09-01 18:24:55 +000051 register_echo_module [sqlite3_connection_pointer db2]
52 db2 eval {
53 CREATE TABLE t1(a, b VARCHAR, c INTEGER);
54 CREATE VIRTUAL TABLE t1echo USING echo(t1);
55 }
56 db2 close
57
58 register_echo_module [sqlite3_connection_pointer db]
59 } -tclbody {
60 set rc [catch {db eval { ALTER TABLE t1echo RENAME TO t1_echo }} msg]
61 if {$msg eq "vtable constructor failed: t1echo"} {
62 set msg "out of memory"
63 }
64 if {$rc} {
65 error $msg
66 }
67 }
68}
69
drh0bbaa1b2005-08-19 19:14:12 +000070finish_test