4 # The author disclaims copyright to this source code. In place of
5 # a legal notice, here is a blessing:
7 # May you do good and not evil.
8 # May you find forgiveness for yourself and forgive others.
9 # May you share freely, never taking more than you give.
11 #***********************************************************************
12 # This file implements regression tests for SQLite library. The
13 # focus of this script is testing the ATTACH and DETACH commands
14 # and related functionality.
16 # $Id: attach2.test,v 1.5 2004/02/12 15:31:22 drh Exp $
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
28 CREATE INDEX x1 ON t1(a);
30 file delete -force test2.db
31 file delete -force test2.db-journal
35 CREATE INDEX x1 ON t1(a);
38 ATTACH 'test2.db' AS t2;
46 foreach {idx name file} [execsql {PRAGMA database_list} $db] {
47 lappend list $idx $name
53 # lock test2.db then try to attach it. Should get an error.
56 ATTACH 'test2.db' AS t2;
58 } {1 {database is locked}}
60 # make sure test2.db did not get attached.
64 # unlock test2.db and try to attach again. should work this time.
67 ATTACH 'test2.db' AS t2;
72 } {0 main 1 temp 2 t2}
75 SELECT name FROM t2.sqlite_master;
79 # lock test2.db and try to read from it. should get an error.
82 SELECT name FROM t2.sqlite_master;
84 } {1 {database is locked}}
86 # but we can still read from test1.db even though test2.db is locked.
88 SELECT name FROM main.sqlite_master;
92 # start a transaction on test.db even though test2.db is locked.
95 INSERT INTO t1 VALUES(8,9);
103 do_test attach2-2.10 {
104 # now try to write to test2.db. the write should fail
106 INSERT INTO t2.t1 VALUES(1,2);
108 } {1 {database is locked}}
109 do_test attach2-2.11 {
110 # when the write failed in the previous test, the transaction should
117 do_test attach2-2.12 {
121 } {1 {cannot commit - no transaction is active}}
123 # Ticket #574: Make sure it works usingi the non-callback API
125 do_test attach2-3.1 {
127 set DB [sqlite db test.db]
128 set rc [catch {sqlite_compile $DB "ATTACH 'test2.db' AS t2" TAIL} VM]
129 if {$rc} {lappend rc $VM}
133 do_test attach2-3.2 {
134 set rc [catch {sqlite_compile $DB "DETACH t2" TAIL} VM]
135 if {$rc} {lappend rc $VM}
141 for {set i 2} {$i<=15} {incr i} {
144 file delete -force test2.db