drh | 0bbaa1b | 2005-08-19 19:14:12 +0000 | [diff] [blame] | 1 | # 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 | # |
danielk1977 | f150c9d | 2008-10-30 17:21:12 +0000 | [diff] [blame] | 15 | # $Id: altermalloc.test,v 1.10 2008/10/30 17:21:13 danielk1977 Exp $ |
drh | 0bbaa1b | 2005-08-19 19:14:12 +0000 | [diff] [blame] | 16 | # |
| 17 | |
| 18 | set testdir [file dirname $argv0] |
| 19 | source $testdir/tester.tcl |
| 20 | |
drh | 0bbaa1b | 2005-08-19 19:14:12 +0000 | [diff] [blame] | 21 | # If SQLITE_OMIT_ALTERTABLE is defined, omit this file. |
drh | da57895 | 2007-08-27 23:48:23 +0000 | [diff] [blame] | 22 | ifcapable !altertable||!memdebug { |
drh | 0bbaa1b | 2005-08-19 19:14:12 +0000 | [diff] [blame] | 23 | finish_test |
| 24 | return |
| 25 | } |
| 26 | |
danielk1977 | cdc3a6b | 2007-08-25 13:09:26 +0000 | [diff] [blame] | 27 | source $testdir/malloc_common.tcl |
drh | 0bbaa1b | 2005-08-19 19:14:12 +0000 | [diff] [blame] | 28 | |
| 29 | do_malloc_test altermalloc-1 -tclprep { |
| 30 | db close |
| 31 | } -tclbody { |
| 32 | if {[catch {sqlite3 db test.db}]} { |
| 33 | error "out of memory" |
| 34 | } |
drh | e9d1c72 | 2008-08-04 20:13:26 +0000 | [diff] [blame] | 35 | sqlite3_db_config_lookaside db 0 0 0 |
danielk1977 | ae72d98 | 2007-10-03 08:46:44 +0000 | [diff] [blame] | 36 | sqlite3_extended_result_codes db 1 |
drh | 0bbaa1b | 2005-08-19 19:14:12 +0000 | [diff] [blame] | 37 | } -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; |
danielk1977 | f150c9d | 2008-10-30 17:21:12 +0000 | [diff] [blame] | 42 | ALTER TABLE t2 ADD COLUMN d BLOB DEFAULT X'ABCD'; |
drh | 0bbaa1b | 2005-08-19 19:14:12 +0000 | [diff] [blame] | 43 | } |
| 44 | |
danielk1977 | 880c15b | 2007-09-01 18:24:55 +0000 | [diff] [blame] | 45 | # Test malloc() failure on an ALTER TABLE on a virtual table. |
| 46 | # |
| 47 | ifcapable vtab { |
| 48 | do_malloc_test altermalloc-vtab -tclprep { |
| 49 | sqlite3 db2 test.db |
drh | e9d1c72 | 2008-08-04 20:13:26 +0000 | [diff] [blame] | 50 | sqlite3_db_config_lookaside db2 0 0 0 |
danielk1977 | ae72d98 | 2007-10-03 08:46:44 +0000 | [diff] [blame] | 51 | sqlite3_extended_result_codes db2 1 |
danielk1977 | 880c15b | 2007-09-01 18:24:55 +0000 | [diff] [blame] | 52 | register_echo_module [sqlite3_connection_pointer db2] |
| 53 | db2 eval { |
| 54 | CREATE TABLE t1(a, b VARCHAR, c INTEGER); |
| 55 | CREATE VIRTUAL TABLE t1echo USING echo(t1); |
| 56 | } |
| 57 | db2 close |
| 58 | |
| 59 | register_echo_module [sqlite3_connection_pointer db] |
| 60 | } -tclbody { |
| 61 | set rc [catch {db eval { ALTER TABLE t1echo RENAME TO t1_echo }} msg] |
| 62 | if {$msg eq "vtable constructor failed: t1echo"} { |
| 63 | set msg "out of memory" |
| 64 | } |
| 65 | if {$rc} { |
| 66 | error $msg |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
drh | 0bbaa1b | 2005-08-19 19:14:12 +0000 | [diff] [blame] | 71 | finish_test |