xref: /sqlite-3.40.0/test/altermalloc.test (revision 880c15be)
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#
15# $Id: altermalloc.test,v 1.6 2007/09/01 18:24:55 danielk1977 Exp $
16#
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
22ifcapable !altertable||!memdebug {
23  finish_test
24  return
25}
26
27source $testdir/malloc_common.tcl
28
29do_malloc_test altermalloc-1 -tclprep {
30  db close
31} -tclbody {
32  if {[catch {sqlite3 db test.db}]} {
33    error "out of memory"
34  }
35} -sqlbody {
36  CREATE TABLE t1(a int);
37  ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL;
38  ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text';
39  ALTER TABLE t1 RENAME TO t2;
40}
41
42# Test malloc() failure on an ALTER TABLE on a virtual table.
43#
44ifcapable vtab {
45  do_malloc_test altermalloc-vtab -tclprep {
46    sqlite3 db2 test.db
47    register_echo_module [sqlite3_connection_pointer db2]
48    db2 eval {
49      CREATE TABLE t1(a, b VARCHAR, c INTEGER);
50      CREATE VIRTUAL TABLE t1echo USING echo(t1);
51    }
52    db2 close
53
54    register_echo_module [sqlite3_connection_pointer db]
55  } -tclbody {
56    set rc [catch {db eval { ALTER TABLE t1echo RENAME TO t1_echo }} msg]
57    if {$msg eq "vtable constructor failed: t1echo"} {
58      set msg "out of memory"
59    }
60    if {$rc} {
61      error $msg
62    }
63  }
64}
65
66finish_test
67