xref: /sqlite-3.40.0/test/altermalloc.test (revision 253c6ee1)
10bbaa1baSdrh# 2005 September 19
20bbaa1baSdrh#
30bbaa1baSdrh# The author disclaims copyright to this source code.  In place of
40bbaa1baSdrh# a legal notice, here is a blessing:
50bbaa1baSdrh#
60bbaa1baSdrh#    May you do good and not evil.
70bbaa1baSdrh#    May you find forgiveness for yourself and forgive others.
80bbaa1baSdrh#    May you share freely, never taking more than you give.
90bbaa1baSdrh#
100bbaa1baSdrh#*************************************************************************
110bbaa1baSdrh# This file implements regression tests for SQLite library.  The
120bbaa1baSdrh# focus of this script is testing the ALTER TABLE statement and
130bbaa1baSdrh# specifically out-of-memory conditions within that command.
140bbaa1baSdrh#
15f150c9deSdanielk1977# $Id: altermalloc.test,v 1.10 2008/10/30 17:21:13 danielk1977 Exp $
160bbaa1baSdrh#
170bbaa1baSdrh
180bbaa1baSdrhset testdir [file dirname $argv0]
190bbaa1baSdrhsource $testdir/tester.tcl
200bbaa1baSdrh
210bbaa1baSdrh# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
22*253c6ee1Sdanifcapable !altertable {
230bbaa1baSdrh  finish_test
240bbaa1baSdrh  return
250bbaa1baSdrh}
260bbaa1baSdrh
27cdc3a6bcSdanielk1977source $testdir/malloc_common.tcl
280bbaa1baSdrh
290bbaa1baSdrhdo_malloc_test altermalloc-1 -tclprep {
300bbaa1baSdrh  db close
310bbaa1baSdrh} -tclbody {
320bbaa1baSdrh  if {[catch {sqlite3 db test.db}]} {
330bbaa1baSdrh    error "out of memory"
340bbaa1baSdrh  }
35e9d1c720Sdrh  sqlite3_db_config_lookaside db 0 0 0
36ae72d982Sdanielk1977  sqlite3_extended_result_codes db 1
370bbaa1baSdrh} -sqlbody {
380bbaa1baSdrh  CREATE TABLE t1(a int);
390bbaa1baSdrh  ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL;
400bbaa1baSdrh  ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text';
410bbaa1baSdrh  ALTER TABLE t1 RENAME TO t2;
42f150c9deSdanielk1977  ALTER TABLE t2 ADD COLUMN d BLOB DEFAULT X'ABCD';
430bbaa1baSdrh}
440bbaa1baSdrh
45880c15beSdanielk1977# Test malloc() failure on an ALTER TABLE on a virtual table.
46880c15beSdanielk1977#
47880c15beSdanielk1977ifcapable vtab {
48880c15beSdanielk1977  do_malloc_test altermalloc-vtab -tclprep {
49880c15beSdanielk1977    sqlite3 db2 test.db
50e9d1c720Sdrh    sqlite3_db_config_lookaside db2 0 0 0
51ae72d982Sdanielk1977    sqlite3_extended_result_codes db2 1
52880c15beSdanielk1977    register_echo_module [sqlite3_connection_pointer db2]
53880c15beSdanielk1977    db2 eval {
54880c15beSdanielk1977      CREATE TABLE t1(a, b VARCHAR, c INTEGER);
55880c15beSdanielk1977      CREATE VIRTUAL TABLE t1echo USING echo(t1);
56880c15beSdanielk1977    }
57880c15beSdanielk1977    db2 close
58880c15beSdanielk1977
59880c15beSdanielk1977    register_echo_module [sqlite3_connection_pointer db]
60880c15beSdanielk1977  } -tclbody {
61880c15beSdanielk1977    set rc [catch {db eval { ALTER TABLE t1echo RENAME TO t1_echo }} msg]
62880c15beSdanielk1977    if {$msg eq "vtable constructor failed: t1echo"} {
63880c15beSdanielk1977      set msg "out of memory"
64880c15beSdanielk1977    }
65880c15beSdanielk1977    if {$rc} {
66880c15beSdanielk1977      error $msg
67880c15beSdanielk1977    }
68880c15beSdanielk1977  }
69880c15beSdanielk1977}
70880c15beSdanielk1977
710bbaa1baSdrhfinish_test
72