More testing of ATTACH and DETACH. (CVS 899)

FossilOrigin-Name: 51f515f28cb1cc3e8f0c3531724dc8876b25f18e
This commit is contained in:
drh 2003-04-05 16:56:28 +00:00
parent 2d4583473b
commit a73af533de
4 changed files with 183 additions and 17 deletions

View File

@ -1,5 +1,5 @@
C Begin\stesting\sthe\snew\sATTACH\sand\sDETACH\scommands.\s(CVS\s898)
D 2003-04-05T03:42:27
C More\stesting\sof\sATTACH\sand\sDETACH.\s(CVS\s899)
D 2003-04-05T16:56:29
F Makefile.in 3c4ba24253e61c954d67adbbb4245e7117c5357e
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@ -22,7 +22,7 @@ F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
F src/auth.c f37bfc9451b8c1fa52f34adff474560018892729
F src/btree.c 7eae5413a7f957bb0733bcab6fab31c6943c51d2
F src/btree.h 024d2dd21310c202d648c6244dec885e48efa9ad
F src/build.c 346e93724f32ec1aa0ed429a004a5e9d7b3372be
F src/build.c 8f158c26c89464e33de4b83a0964042462ea9977
F src/delete.c 58d698779a6b7f819718ecd45b310a9de8537088
F src/encode.c faf03741efe921755ec371cf4a6984536de00042
F src/expr.c b8daee83f837b24a22d889200bdd74973ca2d8db
@ -58,7 +58,7 @@ F src/vdbe.c 540c480912e11e23f5c08a31b8b3594df016f4d1
F src/vdbe.h 985c24f312d10f9ef8f9a8b8ea62fcdf68e82f21
F src/where.c e5733f7d5e9cc4ed3590dc3401f779e7b7bb8127
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
F test/attach.test 93414915d0c27f4e5a384b61792591cd4757fcca
F test/attach.test 4912f001bf807b898083cfdef0f6d24f1533e4d7
F test/auth.test bf039c94d629f64085c268e8be477fc8ff1202a7
F test/bigfile.test 1cd8256d4619c39bea48147d344f348823e78678
F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
@ -157,7 +157,7 @@ F www/speed.tcl cb4c10a722614aea76d2c51f32ee43400d5951be
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
P 452128c6fd9a0d82bfab21374fc2041638d264db
R a56a50d034078b39c733a78422380132
P 7a0f8024a1323a15d0c83afe9302400736f01fe8
R 46fc1ff8621b9b0935cd818bb39b2c75
U drh
Z 584b6bf3cd679c184cb1aafc492c3c1b
Z a79dcf89f73a5ac08f2e57c1e7e0b648

View File

@ -1 +1 @@
7a0f8024a1323a15d0c83afe9302400736f01fe8
51f515f28cb1cc3e8f0c3531724dc8876b25f18e

View File

@ -25,7 +25,7 @@
** ROLLBACK
** PRAGMA
**
** $Id: build.c,v 1.140 2003/04/05 03:42:27 drh Exp $
** $Id: build.c,v 1.141 2003/04/05 16:56:29 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -2613,6 +2613,24 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
}
}else
if( sqliteStrICmp(zLeft, "database_list")==0 ){
int i;
static VdbeOp indexListPreface[] = {
{ OP_ColumnName, 0, 0, "seq"},
{ OP_ColumnName, 1, 0, "name"},
};
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
for(i=0; i<db->nDb; i++){
if( db->aDb[i].pBt==0 ) continue;
assert( db->aDb[i].zName!=0 );
sqliteVdbeAddOp(v, OP_Integer, i, 0);
sqliteVdbeAddOp(v, OP_String, 0, 0);
sqliteVdbeChangeP3(v, -1, db->aDb[i].zName, P3_STATIC);
sqliteVdbeAddOp(v, OP_Callback, 2, 0);
}
}else
#ifndef NDEBUG
if( sqliteStrICmp(zLeft, "parser_trace")==0 ){
extern void sqliteParserTrace(FILE*, char *);
@ -2673,11 +2691,13 @@ void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname){
if( db->file_format<4 ){
sqliteErrorMsg(pParse, "cannot attach auxiliary databases to an "
"older format master database", 0);
pParse->rc = SQLITE_ERROR;
return;
}
if( db->nDb>=MAX_ATTACHED ){
if( db->nDb>=MAX_ATTACHED+2 ){
sqliteErrorMsg(pParse, "too many attached databases - max %d",
MAX_ATTACHED);
pParse->rc = SQLITE_ERROR;
return;
}
if( db->aDb==db->aDbStatic ){
@ -2703,6 +2723,8 @@ void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname){
for(i=0; i<db->nDb; i++){
if( db->aDb[i].zName && sqliteStrICmp(db->aDb[i].zName, zName)==0 ){
sqliteErrorMsg(pParse, "database %z is already in use", zName);
db->nDb--;
pParse->rc = SQLITE_ERROR;
return;
}
}
@ -2722,6 +2744,7 @@ void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname){
if( rc ){
sqliteResetInternalSchema(db, 0);
pParse->nErr++;
pParse->rc = SQLITE_ERROR;
}
}
@ -2748,10 +2771,16 @@ void sqliteDetach(Parse *pParse, Token *pDbname){
return;
}
if( i<2 ){
sqliteErrorMsg(pParse, "cannot detached database %T", pDbname);
sqliteErrorMsg(pParse, "cannot detach database %T", pDbname);
return;
}
sqliteBtreeClose(db->aDb[i].pBt);
db->aDb[i].pBt = 0;
sqliteResetInternalSchema(db, 0);
sqliteResetInternalSchema(db, i);
db->nDb--;
if( i<db->nDb ){
db->aDb[i] = db->aDb[db->nDb];
memset(&db->aDb[db->nDb], 0, sizeof(db->aDb[0]));
sqliteResetInternalSchema(db, i);
}
}

View File

@ -12,14 +12,16 @@
# focus of this script is testing the ATTACH and DETACH commands
# and related functionality.
#
# $Id: attach.test,v 1.1 2003/04/05 03:42:27 drh Exp $
# $Id: attach.test,v 1.2 2003/04/05 16:56:30 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
file delete -force test2.db
file delete -force test2.db-journal
for {set i 2} {$i<=15} {incr i} {
file delete -force test$i.db
file delete -force test$i.db-journal
}
do_test attach-1.1 {
execsql {
@ -36,7 +38,7 @@ do_test attach-1.2 {
INSERT INTO t2 VALUES(1,'x');
INSERT INTO t2 VALUES(2,'y');
SELECT * FROM t2;
}
} db2
} {1 x 2 y}
do_test attach-1.3 {
execsql {
@ -65,8 +67,143 @@ do_test attach-1.7 {
SELECT * FROM two.t2;
}
} {1 {no such table: two.t2}}
do_test attach-1.8 {
catchsql {
ATTACH DATABASE 'test3.db' AS three;
}
} {1 {cannot attach empty database: three}}
do_test attach-1.9 {
catchsql {
SELECT * FROM three.sqlite_master;
}
} {1 {no such table: three.sqlite_master}}
do_test attach-1.10 {
catchsql {
DETACH DATABASE three;
}
} {1 {no such database: three}}
do_test attach-1.11 {
execsql {
ATTACH 'test.db' AS db2;
ATTACH 'test.db' AS db3;
ATTACH 'test.db' AS db4;
ATTACH 'test.db' AS db5;
ATTACH 'test.db' AS db6;
ATTACH 'test.db' AS db7;
ATTACH 'test.db' AS db8;
ATTACH 'test.db' AS db9;
}
} {}
do_test attach-1.11b {
execsql {
PRAGMA database_list;
}
} {0 main 1 temp 2 db2 3 db3 4 db4 5 db5 6 db6 7 db7 8 db8 9 db9}
do_test attach-1.12 {
catchsql {
ATTACH 'test.db' as db2;
}
} {1 {database db2 is already in use}}
do_test attach-1.13 {
catchsql {
ATTACH 'test.db' as db5;
}
} {1 {database db5 is already in use}}
do_test attach-1.14 {
catchsql {
ATTACH 'test.db' as db9;
}
} {1 {database db9 is already in use}}
do_test attach-1.15 {
catchsql {
ATTACH 'test.db' as main;
}
} {1 {database main is already in use}}
do_test attach-1.16 {
catchsql {
ATTACH 'test.db' as temp;
}
} {1 {database temp is already in use}}
do_test attach-1.17 {
catchsql {
ATTACH 'test.db' as MAIN;
}
} {1 {database MAIN is already in use}}
do_test attach-1.18 {
catchsql {
ATTACH 'test.db' as db10;
ATTACH 'test.db' as db11;
}
} {0 {}}
do_test attach-1.19 {
catchsql {
ATTACH 'test.db' as db12;
}
} {1 {too many attached databases - max 10}}
do_test attach-1.20 {
execsql {
DETACH db5;
PRAGMA database_list;
}
} {0 main 1 temp 2 db2 3 db3 4 db4 5 db11 6 db6 7 db7 8 db8 9 db9 10 db10}
do_test attach-1.21 {
catchsql {
ATTACH 'test.db' as db12;
}
} {0 {}}
do_test attach-1.22 {
catchsql {
ATTACH 'test.db' as db13;
}
} {1 {too many attached databases - max 10}}
do_test attach-1.23 {
catchsql {
DETACH db14;
}
} {1 {no such database: db14}}
do_test attach-1.24 {
catchsql {
DETACH db12;
}
} {0 {}}
do_test attach-1.25 {
catchsql {
DETACH db12;
}
} {1 {no such database: db12}}
do_test attach-1.26 {
catchsql {
DETACH main;
}
} {1 {cannot detach database main}}
do_test attach-1.27 {
catchsql {
DETACH Temp;
}
} {1 {cannot detach database Temp}}
do_test attach-1.28 {
catchsql {
DETACH db11;
DETACH db10;
DETACH db9;
DETACH db8;
DETACH db7;
DETACH db6;
DETACH db4;
DETACH db3;
DETACH db2;
}
} {0 {}}
do_test attach-1.29 {
execsql {
PRAGMA database_list
}
} {0 main 1 temp}
db2 close
for {set i 2} {$i<=15} {incr i} {
catch {db$i close}
}
finish_test