-C Always\suse\s"(char*)0"\sto\sterminate\sthe\sargument\slist\sof\ssqliteSetString().\nThis\sis\sneeded\sfor\s64-bit\ssystems\sthat\suse\sa\s32-bit\sinteger\sby\sdefault.\s(CVS\s1126)
-D 2003-12-06T21:43:56
+C Fail\san\sATTACH\sif\sthe\sauxiliary\sdatabase\sis\slocked.\s\sTicket\s#514.\s(CVS\s1127)
+D 2003-12-06T22:22:36
F Makefile.in 5cb273b7d0e945d47ee8b9ad1c2a04ce79927d2d
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
F spec.template a38492f1c1dd349fc24cb0565e08afc53045304b
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
-F src/attach.c 9f78b4aaac02a2b09ff108e92cbaee3199e7962a
+F src/attach.c 9a3764bbccb1c8b39321630006fbaa0fb8bd1822
F src/auth.c c59ad0dab501888f8b1fccc25e2f5965d2265116
F src/btree.c bcb466c2939582a3a62f577cd8a9e5d637f3698d
F src/btree.h 9b7c09f1e64274d7bb74a57bbfc63778f67b1048
F src/where.c d01a3506f3c1e3a205028068c8a14d713872c633
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
F test/attach.test c26848402e7ac829e043e1fa5e0eb87032e5d81d
-F test/attach2.test 6f98cc2b929d88dc5f82d95d04e9b89b3b5dead3
+F test/attach2.test d0105f4e8b1debf0ac25ed7df986b5854620e172
F test/auth.test b7d6bdeffa804b96b7bcac2712e5f71ce014a1b8
F test/bigfile.test 1cd8256d4619c39bea48147d344f348823e78678
F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
-P e5e6a8481b2225e826c8e890ddc44f06759fe72b
-R 486b33d90c9358024a2965d7fdcc35e3
+P 656c90387a4a714b4f31040ece9b0e15e30934af
+R 9ba0dba1a5b0b6a0c4f493ffeeb808ce
U drh
-Z 6d642432b480eb97ee7365de7928480a
+Z 4d2d90a1bb0f4a7af58cf43ec43a116f
-656c90387a4a714b4f31040ece9b0e15e30934af
\ No newline at end of file
+ac428c8d4a731678cc26cf198689814a8a56d141
\ No newline at end of file
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
-** $Id: attach.c,v 1.7 2003/06/14 12:04:08 drh Exp $
+** $Id: attach.c,v 1.8 2003/12/06 22:22:36 drh Exp $
*/
#include "sqliteInt.h"
sqliteFree(zFile);
db->flags &= ~SQLITE_Initialized;
if( pParse->nErr ) return;
- rc = sqliteInit(pParse->db, &pParse->zErrMsg);
+ if( rc==SQLITE_OK ){
+ rc = sqliteInit(pParse->db, &pParse->zErrMsg);
+ }
if( rc ){
+ int i = db->nDb - 1;
+ assert( i>=2 );
+ if( db->aDb[i].pBt ){
+ sqliteBtreeClose(db->aDb[i].pBt);
+ db->aDb[i].pBt = 0;
+ }
sqliteResetInternalSchema(db, 0);
pParse->nErr++;
pParse->rc = SQLITE_ERROR;
# 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 $
#
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);
}
} {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}