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

Disallow attaching the same database multiple times to the same db connection

in shared cache mode, since doing so leads to deadlock. (CVS 6578)

FossilOrigin-Name: 715f14f1dcaf604d4794bf3e18e245d4f8c5d5a9
This commit is contained in:
drh
2009-04-30 13:30:32 +00:00
parent 9b3c24d15d
commit c47fd8e031
5 changed files with 89 additions and 12 deletions

View File

@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.87 2009/04/30 05:40:34 drh Exp $
** $Id: attach.c,v 1.88 2009/04/30 13:30:33 drh Exp $
*/
#include "sqliteInt.h"
@@ -119,7 +119,7 @@ static void attachFunc(
if( aNew==0 ) return;
}
db->aDb = aNew;
aNew = &db->aDb[db->nDb++];
aNew = &db->aDb[db->nDb];
memset(aNew, 0, sizeof(*aNew));
/* Open the database file. If the btree is successfully opened, use
@@ -129,7 +129,11 @@ static void attachFunc(
rc = sqlite3BtreeFactory(db, zFile, 0, SQLITE_DEFAULT_CACHE_SIZE,
db->openFlags | SQLITE_OPEN_MAIN_DB,
&aNew->pBt);
if( rc==SQLITE_OK ){
db->nDb++;
if( rc==SQLITE_CONSTRAINT ){
rc = SQLITE_ERROR;
zErrDyn = sqlite3MPrintf(db, "database is already attached");
}else if( rc==SQLITE_OK ){
Pager *pPager;
aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
if( !aNew->pSchema ){