Fix a problem causing the recovery extension to use excessive memory and CPU time...
[sqlite.git] / test / attachmalloc.test
blob3c6a075b43bbc2a9b32def3f233b7289257382bb
1 # 2005 September 19
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
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.
15 # $Id: attachmalloc.test,v 1.10 2008/10/22 10:45:38 danielk1977 Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 ifcapable !attach {
22   finish_test
23   return
26 source $testdir/malloc_common.tcl
28 do_malloc_test attachmalloc-1 -tclprep {
29   catch { db close }
30   for {set i 2} {$i<=4} {incr i} {
31     catch { db$i close }
32     forcedelete test$i.db
33     forcedelete test$i.db-journal
34   }
35 } -tclbody {
36   if {[catch {sqlite3 db test.db}]} {
37     error "out of memory"
38   }
39   sqlite3_db_config_lookaside db 0 0 0
40   sqlite3_extended_result_codes db 1
41 } -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);
50 do_malloc_test attachmalloc-2 -tclprep {
51   forcedelete test2.db
52   forcedelete test2.db-journal
53   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;
64 ifcapable shared_cache {
65   set enable_shared_cache [sqlite3_enable_shared_cache 1]
66   sqlite3 dbaux test3.db
67   dbaux eval {SELECT * FROM sqlite_master}
68   do_malloc_test attachmalloc-3 -sqlbody {
69     SELECT * FROM sqlite_master;
70     ATTACH 'test3.db' AS three;
71   } -cleanup {
72     db eval { DETACH three }
73   }
74   dbaux close
75   sqlite3_enable_shared_cache $enable_shared_cache
78 finish_test