2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
9 # May you do good and not evil.
10 # May you find forgiveness for yourself and forgive others.
11 # May you share freely, never taking more than you give.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library. The
15 # focus of this script is testing the ATTACH and DETACH commands
16 # and related functionality.
18 # $Id: attach2.test,v 1.5 2004/02/12 15:31:22 drh Exp $
22 set testdir [file dirname $argv0]
23 source $testdir/tester.tcl
30 CREATE INDEX x1 ON t1(a);
32 file delete -force test2.db
33 file delete -force test2.db-journal
37 CREATE INDEX x1 ON t1(a);
40 ATTACH 'test2.db' AS t2;
48 foreach {idx name file} [execsql {PRAGMA database_list} $db] {
49 lappend list $idx $name
55 # lock test2.db then try to attach it. Should get an error.
58 ATTACH 'test2.db' AS t2;
60 } {1 {database is locked}}
62 # make sure test2.db did not get attached.
66 # unlock test2.db and try to attach again. should work this time.
69 ATTACH 'test2.db' AS t2;
74 } {0 main 1 temp 2 t2}
77 SELECT name FROM t2.sqlite_master;
81 # lock test2.db and try to read from it. should get an error.
84 SELECT name FROM t2.sqlite_master;
86 } {1 {database is locked}}
88 # but we can still read from test1.db even though test2.db is locked.
90 SELECT name FROM main.sqlite_master;
94 # start a transaction on test.db even though test2.db is locked.
97 INSERT INTO t1 VALUES(8,9);
100 do_test attach2-2.9 {
105 do_test attach2-2.10 {
106 # now try to write to test2.db. the write should fail
108 INSERT INTO t2.t1 VALUES(1,2);
110 } {1 {database is locked}}
111 do_test attach2-2.11 {
112 # when the write failed in the previous test, the transaction should
119 do_test attach2-2.12 {
123 } {1 {cannot commit - no transaction is active}}
125 # Ticket #574: Make sure it works usingi the non-callback API
127 do_test attach2-3.1 {
129 set DB [sqlite db test.db]
130 set rc [catch {sqlite_compile $DB "ATTACH 'test2.db' AS t2" TAIL} VM]
131 if {$rc} {lappend rc $VM}
135 do_test attach2-3.2 {
136 set rc [catch {sqlite_compile $DB "DETACH t2" TAIL} VM]
137 if {$rc} {lappend rc $VM}
143 for {set i 2} {$i<=15} {incr i} {
146 file delete -force test2.db