Fail an ATTACH if the auxiliary database is locked. Ticket #514. (CVS 1127)
FossilOrigin-Name: ac428c8d4a731678cc26cf198689814a8a56d141
This commit is contained in:
+82
-1
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach2.test,v 1.2 2003/07/18 01:25:35 drh Exp $
|
||||
# $Id: attach2.test,v 1.3 2003/12/06 22:22:37 drh Exp $
|
||||
#
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ do_test attach2-1.1 {
|
||||
CREATE INDEX x1 ON t1(a);
|
||||
}
|
||||
file delete -force test2.db
|
||||
file delete -force test2.db-journal
|
||||
sqlite db2 test2.db
|
||||
db2 eval {
|
||||
CREATE TABLE t1(a,b);
|
||||
@@ -37,6 +38,86 @@ do_test attach2-1.1 {
|
||||
}
|
||||
} {0 {}}
|
||||
|
||||
# Ticket #514
|
||||
#
|
||||
proc db_list {db} {
|
||||
set list {}
|
||||
foreach {idx name file} [execsql {PRAGMA database_list} $db] {
|
||||
lappend list $idx $name
|
||||
}
|
||||
return $list
|
||||
}
|
||||
db eval {DETACH t2}
|
||||
do_test attach2-2.1 {
|
||||
# lock test2.db then try to attach it. Should get an error.
|
||||
db2 eval {BEGIN}
|
||||
catchsql {
|
||||
ATTACH 'test2.db' AS t2;
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
do_test attach2-2.2 {
|
||||
# make sure test2.db did not get attached.
|
||||
db_list db
|
||||
} {0 main 1 temp}
|
||||
do_test attach2-2.3 {
|
||||
# unlock test2.db and try to attach again. should work this time.
|
||||
db2 eval {COMMIT}
|
||||
catchsql {
|
||||
ATTACH 'test2.db' AS t2;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach2-2.4 {
|
||||
db_list db
|
||||
} {0 main 1 temp 2 t2}
|
||||
do_test attach2-2.5 {
|
||||
catchsql {
|
||||
SELECT name FROM t2.sqlite_master;
|
||||
}
|
||||
} {0 {t1 x1}}
|
||||
do_test attach2-2.6 {
|
||||
# lock test2.db and try to read from it. should get an error.
|
||||
db2 eval BEGIN
|
||||
catchsql {
|
||||
SELECT name FROM t2.sqlite_master;
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
do_test attach2-2.7 {
|
||||
# but we can still read from test1.db even though test2.db is locked.
|
||||
catchsql {
|
||||
SELECT name FROM main.sqlite_master;
|
||||
}
|
||||
} {0 {t1 x1}}
|
||||
do_test attach2-2.8 {
|
||||
# start a transaction on test.db even though test2.db is locked.
|
||||
catchsql {
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES(8,9);
|
||||
}
|
||||
} {0 {}}
|
||||
do_test attach2-2.9 {
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {8 9}
|
||||
do_test attach2-2.10 {
|
||||
# now try to write to test2.db. the write should fail
|
||||
catchsql {
|
||||
INSERT INTO t2.t1 VALUES(1,2);
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
do_test attach2-2.11 {
|
||||
# when the write failed in the previous test, the transaction should
|
||||
# have rolled back.
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {}
|
||||
do_test attach2-2.12 {
|
||||
catchsql {
|
||||
COMMIT
|
||||
}
|
||||
} {1 {cannot commit - no transaction is active}}
|
||||
|
||||
db close
|
||||
for {set i 2} {$i<=15} {incr i} {
|
||||
catch {db$i close}
|
||||
|
||||
Reference in New Issue
Block a user