blob: 7fee1e1b2a9ddaf536095d6e5de8e64647fdeef8 [file] [log] [blame]
drh85c23c62005-08-20 03:03:04 +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 ATTACH statement and
13# specifically out-of-memory conditions within that command.
14#
danielk1977d207d802008-10-22 10:45:37 +000015# $Id: attachmalloc.test,v 1.10 2008/10/22 10:45:38 danielk1977 Exp $
drh85c23c62005-08-20 03:03:04 +000016#
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
danielk19775a8f9372007-10-09 08:29:32 +000021ifcapable !memdebug||!attach {
drhda578952007-08-27 23:48:23 +000022 finish_test
23 return
24}
25
danielk1977222a7572007-08-25 13:37:48 +000026source $testdir/malloc_common.tcl
drh85c23c62005-08-20 03:03:04 +000027
28do_malloc_test attachmalloc-1 -tclprep {
shanehf922d712010-11-04 20:46:09 +000029 catch { db close }
drh85c23c62005-08-20 03:03:04 +000030 for {set i 2} {$i<=4} {incr i} {
shanehf922d712010-11-04 20:46:09 +000031 catch { db$i close }
mistachkinfda06be2011-08-02 00:57:34 +000032 forcedelete test$i.db
33 forcedelete test$i.db-journal
drh85c23c62005-08-20 03:03:04 +000034 }
35} -tclbody {
36 if {[catch {sqlite3 db test.db}]} {
37 error "out of memory"
38 }
drhe9d1c722008-08-04 20:13:26 +000039 sqlite3_db_config_lookaside db 0 0 0
danielk1977ae72d982007-10-03 08:46:44 +000040 sqlite3_extended_result_codes db 1
drh85c23c62005-08-20 03:03:04 +000041} -sqlbody {
42 ATTACH 'test2.db' AS two;
43 CREATE TABLE two.t1(x);
44 ATTACH 'test3.db' AS three;
45 CREATE TABLE three.t1(x);
46 ATTACH 'test4.db' AS four;
47 CREATE TABLE four.t1(x);
48}
49
danielk1977d207d802008-10-22 10:45:37 +000050do_malloc_test attachmalloc-2 -tclprep {
mistachkinfda06be2011-08-02 00:57:34 +000051 forcedelete test2.db
52 forcedelete test2.db-journal
danielk1977d207d802008-10-22 10:45:37 +000053 sqlite3 db2 test2.db
54 db2 eval {
55 CREATE TABLE t1(a, b, c);
56 CREATE INDEX i1 ON t1(a, b);
57 }
58 db2 close
59} -sqlbody {
60 CREATE TABLE t1(d, e, f);
61 ATTACH 'test2.db' AS db1;
62}
63
dan39547b42010-02-23 11:05:26 +000064set enable_shared_cache [sqlite3_enable_shared_cache 1]
shanehf922d712010-11-04 20:46:09 +000065sqlite3 dbaux test3.db
dan39547b42010-02-23 11:05:26 +000066dbaux eval {SELECT * FROM sqlite_master}
67do_malloc_test attachmalloc-3 -sqlbody {
68 SELECT * FROM sqlite_master;
shanehf922d712010-11-04 20:46:09 +000069 ATTACH 'test3.db' AS three;
dan39547b42010-02-23 11:05:26 +000070} -cleanup {
shanehf922d712010-11-04 20:46:09 +000071 db eval { DETACH three }
dan39547b42010-02-23 11:05:26 +000072}
73dbaux close
74sqlite3_enable_shared_cache $enable_shared_cache
75
76
drh85c23c62005-08-20 03:03:04 +000077finish_test