1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

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:
drh
2006-05-25 11:52:37 +00:00
parent f012ea3b00
commit ea063f5bb1
4 changed files with 111 additions and 18 deletions

View File

@@ -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 ){