185c23c61Sdrh# 2005 September 19 285c23c61Sdrh# 385c23c61Sdrh# The author disclaims copyright to this source code. In place of 485c23c61Sdrh# a legal notice, here is a blessing: 585c23c61Sdrh# 685c23c61Sdrh# May you do good and not evil. 785c23c61Sdrh# May you find forgiveness for yourself and forgive others. 885c23c61Sdrh# May you share freely, never taking more than you give. 985c23c61Sdrh# 1085c23c61Sdrh#************************************************************************* 1185c23c61Sdrh# This file implements regression tests for SQLite library. The 1285c23c61Sdrh# focus of this script is testing the ATTACH statement and 1385c23c61Sdrh# specifically out-of-memory conditions within that command. 1485c23c61Sdrh# 15d207d808Sdanielk1977# $Id: attachmalloc.test,v 1.10 2008/10/22 10:45:38 danielk1977 Exp $ 1685c23c61Sdrh# 1785c23c61Sdrh 1885c23c61Sdrhset testdir [file dirname $argv0] 1985c23c61Sdrhsource $testdir/tester.tcl 2085c23c61Sdrh 215a8f9374Sdanielk1977ifcapable !memdebug||!attach { 22da57895fSdrh finish_test 23da57895fSdrh return 24da57895fSdrh} 25da57895fSdrh 26222a757dSdanielk1977source $testdir/malloc_common.tcl 2785c23c61Sdrh 2885c23c61Sdrhdo_malloc_test attachmalloc-1 -tclprep { 29f922d715Sshaneh catch { db close } 3085c23c61Sdrh for {set i 2} {$i<=4} {incr i} { 31f922d715Sshaneh catch { db$i close } 32*fda06befSmistachkin forcedelete test$i.db 33*fda06befSmistachkin forcedelete test$i.db-journal 3485c23c61Sdrh } 3585c23c61Sdrh} -tclbody { 3685c23c61Sdrh if {[catch {sqlite3 db test.db}]} { 3785c23c61Sdrh error "out of memory" 3885c23c61Sdrh } 39e9d1c720Sdrh sqlite3_db_config_lookaside db 0 0 0 40ae72d982Sdanielk1977 sqlite3_extended_result_codes db 1 4185c23c61Sdrh} -sqlbody { 4285c23c61Sdrh ATTACH 'test2.db' AS two; 4385c23c61Sdrh CREATE TABLE two.t1(x); 4485c23c61Sdrh ATTACH 'test3.db' AS three; 4585c23c61Sdrh CREATE TABLE three.t1(x); 4685c23c61Sdrh ATTACH 'test4.db' AS four; 4785c23c61Sdrh CREATE TABLE four.t1(x); 4885c23c61Sdrh} 4985c23c61Sdrh 50d207d808Sdanielk1977do_malloc_test attachmalloc-2 -tclprep { 51*fda06befSmistachkin forcedelete test2.db 52*fda06befSmistachkin forcedelete test2.db-journal 53d207d808Sdanielk1977 sqlite3 db2 test2.db 54d207d808Sdanielk1977 db2 eval { 55d207d808Sdanielk1977 CREATE TABLE t1(a, b, c); 56d207d808Sdanielk1977 CREATE INDEX i1 ON t1(a, b); 57d207d808Sdanielk1977 } 58d207d808Sdanielk1977 db2 close 59d207d808Sdanielk1977} -sqlbody { 60d207d808Sdanielk1977 CREATE TABLE t1(d, e, f); 61d207d808Sdanielk1977 ATTACH 'test2.db' AS db1; 62d207d808Sdanielk1977} 63d207d808Sdanielk1977 6439547b41Sdanset enable_shared_cache [sqlite3_enable_shared_cache 1] 65f922d715Sshanehsqlite3 dbaux test3.db 6639547b41Sdandbaux eval {SELECT * FROM sqlite_master} 6739547b41Sdando_malloc_test attachmalloc-3 -sqlbody { 6839547b41Sdan SELECT * FROM sqlite_master; 69f922d715Sshaneh ATTACH 'test3.db' AS three; 7039547b41Sdan} -cleanup { 71f922d715Sshaneh db eval { DETACH three } 7239547b41Sdan} 7339547b41Sdandbaux close 7439547b41Sdansqlite3_enable_shared_cache $enable_shared_cache 7539547b41Sdan 7639547b41Sdan 7785c23c61Sdrhfinish_test 78