Handle NULL database names in ATTACH and DETACH as if they were empty
strings. Ticket #1825. (CVS 3191) FossilOrigin-Name: 79a818bb05bc95c4c83375a679955dd18659b2b8
This commit is contained in:
parent
f012ea3b00
commit
ea063f5bb1
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C When\sopening\sa\snew\sconnection\son\sa\sshared\scache,\sbe\scareful\snot\sto\noverwrite\sthe\sencoding\sflag\son\sthe\sshared\scache.\s\sTicket\s#1824.\s(CVS\s3190)
|
||||
D 2006-05-24T12:43:27
|
||||
C Handle\sNULL\sdatabase\snames\sin\sATTACH\sand\sDETACH\sas\sif\sthey\swere\sempty\nstrings.\s\sTicket\s#1825.\s(CVS\s3191)
|
||||
D 2006-05-25T11:52:38
|
||||
F Makefile.in 5d8dff443383918b700e495de42ec65bc1c8865b
|
||||
F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec
|
||||
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
|
||||
@ -32,7 +32,7 @@ F sqlite3.def f756049b1bf3e8442baf6862db393ca423225262
|
||||
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
|
||||
F src/alter.c 451b34fc4eb2475ca76a2e86b21e1030a9428091
|
||||
F src/analyze.c 7d2b7ab9a9c2fd6e55700f69064dfdd3e36d7a8a
|
||||
F src/attach.c 765217a681eb0fb68f95f372604d4fa4594a503f
|
||||
F src/attach.c 27a31d3b89d7ebb5b358847607b1ec795384123c
|
||||
F src/auth.c 9ae84d2d94eb96195e04515715e08e85963e96c2
|
||||
F src/btree.c ed343b3dbcbc7da9ac481ef2b98c4239fe6d9629
|
||||
F src/btree.h 40055cfc09defd1146bc5b922399c035f969e56d
|
||||
@ -109,7 +109,7 @@ F test/async.test 464dc7c7ccb144e8c82ecca429e6d7cd1c96bd6e
|
||||
F test/async2.test 81e4a1fd010c903eb3b763fdb4c4cad7a99afb14
|
||||
F test/attach.test 036315207c477211470168bf121b1c493f781515
|
||||
F test/attach2.test 0e6a7c54343c85dd877a1e86073a05176043ed40
|
||||
F test/attach3.test 63013383adc4380af69779f34f4af19bd49f7cbe
|
||||
F test/attach3.test fc0302e8fe9c172fb49e000227c19b5c428a9429
|
||||
F test/attachmalloc.test cdb26c42850f04698377ccec05f5fa89d987837c
|
||||
F test/auth.test 9776ab43de94801f0fa6787b3f3e803686ffa0ff
|
||||
F test/autoinc.test 60005a676e3e4e17dfa9dbd08aa0b76587ff97e3
|
||||
@ -356,7 +356,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
|
||||
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
||||
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
|
||||
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
|
||||
P b93e3fb02aeff7fe6cae56c3a45c43ffdb2f030b
|
||||
R 6f1ef5bdf0e46314fcf96d09a1927ff3
|
||||
P c8e5ceedee087098c04e3b6b8b82710de0563e77
|
||||
R 92b272fc10eef000585a2fbf978f3171
|
||||
U drh
|
||||
Z 3023c12e4514d7a00d29c00958bc4963
|
||||
Z a97a523d146f3a82e0903b8c989a26c5
|
||||
|
@ -1 +1 @@
|
||||
c8e5ceedee087098c04e3b6b8b82710de0563e77
|
||||
79a818bb05bc95c4c83375a679955dd18659b2b8
|
20
src/attach.c
20
src/attach.c
@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the ATTACH and DETACH commands.
|
||||
**
|
||||
** $Id: attach.c,v 1.51 2006/04/10 13:37:47 drh Exp $
|
||||
** $Id: attach.c,v 1.52 2006/05/25 11:52:38 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@ -73,6 +73,8 @@ static void attachFunc(
|
||||
|
||||
zFile = (const char *)sqlite3_value_text(argv[0]);
|
||||
zName = (const char *)sqlite3_value_text(argv[1]);
|
||||
if( zFile==0 ) zFile = "";
|
||||
if( zName==0 ) zName = "";
|
||||
|
||||
/* Check for the following errors:
|
||||
**
|
||||
@ -82,7 +84,7 @@ static void attachFunc(
|
||||
*/
|
||||
if( db->nDb>=MAX_ATTACHED+2 ){
|
||||
sqlite3_snprintf(
|
||||
127, zErr, "too many attached databases - max %d", MAX_ATTACHED
|
||||
sizeof(zErr), zErr, "too many attached databases - max %d", MAX_ATTACHED
|
||||
);
|
||||
goto attach_error;
|
||||
}
|
||||
@ -92,8 +94,8 @@ static void attachFunc(
|
||||
}
|
||||
for(i=0; i<db->nDb; i++){
|
||||
char *z = db->aDb[i].zName;
|
||||
if( z && sqlite3StrICmp(z, zName)==0 ){
|
||||
sqlite3_snprintf(127, zErr, "database %s is already in use", zName);
|
||||
if( z && zName && sqlite3StrICmp(z, zName)==0 ){
|
||||
sqlite3_snprintf(sizeof(zErr), zErr, "database %s is already in use", zName);
|
||||
goto attach_error;
|
||||
}
|
||||
}
|
||||
@ -187,9 +189,9 @@ static void attachFunc(
|
||||
db->nDb = iDb;
|
||||
if( rc==SQLITE_NOMEM ){
|
||||
if( !sqlite3MallocFailed() ) sqlite3FailedMalloc();
|
||||
sqlite3_snprintf(127, zErr, "out of memory");
|
||||
sqlite3_snprintf(sizeof(zErr),zErr, "out of memory");
|
||||
}else{
|
||||
sqlite3_snprintf(127, zErr, "unable to open database: %s", zFile);
|
||||
sqlite3_snprintf(sizeof(zErr),zErr, "unable to open database: %s", zFile);
|
||||
}
|
||||
goto attach_error;
|
||||
}
|
||||
@ -226,7 +228,7 @@ static void detachFunc(
|
||||
Db *pDb = 0;
|
||||
char zErr[128];
|
||||
|
||||
assert(zName);
|
||||
if( zName==0 ) zName = "";
|
||||
for(i=0; i<db->nDb; i++){
|
||||
pDb = &db->aDb[i];
|
||||
if( pDb->pBt==0 ) continue;
|
||||
@ -234,11 +236,11 @@ static void detachFunc(
|
||||
}
|
||||
|
||||
if( i>=db->nDb ){
|
||||
sqlite3_snprintf(sizeof(zErr), zErr, "no such database: %s", zName);
|
||||
sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
|
||||
goto detach_error;
|
||||
}
|
||||
if( i<2 ){
|
||||
sqlite3_snprintf(sizeof(zErr), zErr, "cannot detach database %s", zName);
|
||||
sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName);
|
||||
goto detach_error;
|
||||
}
|
||||
if( !db->autoCommit ){
|
||||
|
@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and schema changes to attached databases.
|
||||
#
|
||||
# $Id: attach3.test,v 1.15 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
# $Id: attach3.test,v 1.16 2006/05/25 11:52:38 drh Exp $
|
||||
#
|
||||
|
||||
|
||||
@ -242,4 +242,95 @@ do_test attach3-11.2 {
|
||||
}
|
||||
} {0 {}}
|
||||
|
||||
# Return a list of attached databases
|
||||
#
|
||||
proc db_list {} {
|
||||
set x [execsql {
|
||||
PRAGMA database_list;
|
||||
}]
|
||||
set y {}
|
||||
foreach {n id file} $x {lappend y $id}
|
||||
return $y
|
||||
}
|
||||
|
||||
# Ticket #1825
|
||||
#
|
||||
do_test attach3-12.1 {
|
||||
db_list
|
||||
} {main temp aux}
|
||||
do_test attach3-12.2 {
|
||||
execsql {
|
||||
ATTACH DATABASE ? AS ?
|
||||
}
|
||||
db_list
|
||||
} {main temp aux {}}
|
||||
do_test attach3-12.3 {
|
||||
execsql {
|
||||
DETACH aux
|
||||
}
|
||||
db_list
|
||||
} {main temp {}}
|
||||
do_test attach3-12.4 {
|
||||
execsql {
|
||||
DETACH ?
|
||||
}
|
||||
db_list
|
||||
} {main temp}
|
||||
do_test attach3-12.5 {
|
||||
execsql {
|
||||
ATTACH DATABASE '' AS ''
|
||||
}
|
||||
db_list
|
||||
} {main temp {}}
|
||||
do_test attach3-12.6 {
|
||||
execsql {
|
||||
DETACH ''
|
||||
}
|
||||
db_list
|
||||
} {main temp}
|
||||
do_test attach3-12.7 {
|
||||
execsql {
|
||||
ATTACH DATABASE '' AS ?
|
||||
}
|
||||
db_list
|
||||
} {main temp {}}
|
||||
do_test attach3-12.8 {
|
||||
execsql {
|
||||
DETACH ''
|
||||
}
|
||||
db_list
|
||||
} {main temp}
|
||||
do_test attach3-12.9 {
|
||||
execsql {
|
||||
ATTACH DATABASE '' AS NULL
|
||||
}
|
||||
db_list
|
||||
} {main temp {}}
|
||||
do_test attach3-12.10 {
|
||||
execsql {
|
||||
DETACH ?
|
||||
}
|
||||
db_list
|
||||
} {main temp}
|
||||
do_test attach3-12.11 {
|
||||
catchsql {
|
||||
DETACH NULL
|
||||
}
|
||||
} {1 {no such database: }}
|
||||
do_test attach3-12.12 {
|
||||
catchsql {
|
||||
ATTACH null AS null;
|
||||
ATTACH '' AS '';
|
||||
}
|
||||
} {1 {database is already in use}}
|
||||
do_test attach3-12.13 {
|
||||
db_list
|
||||
} {main temp {}}
|
||||
do_test attach3-12.14 {
|
||||
execsql {
|
||||
DETACH '';
|
||||
}
|
||||
db_list
|
||||
} {main temp}
|
||||
|
||||
finish_test
|
||||
|
Loading…
Reference in New Issue
Block a user