1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Additional testing of the ATTACH command with bug fixes for the new problems

that the tests found. (CVS 998)

FossilOrigin-Name: 3e8889d7ce5e99fc855526fc1bb62ddbe282bfc5
This commit is contained in:
drh
2003-06-03 01:47:11 +00:00
parent 1aa4965ae3
commit 4312db55d9
8 changed files with 168 additions and 28 deletions

View File

@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.4 2003/05/31 16:21:12 drh Exp $
** $Id: attach.c,v 1.5 2003/06/03 01:47:11 drh Exp $
*/
#include "sqliteInt.h"
@ -148,6 +148,7 @@ int sqliteFixInit(
if( iDb<0 || iDb==1 ) return 0;
db = pParse->db;
assert( db->nDb>iDb );
pFix->pParse = pParse;
pFix->zDb = db->aDb[iDb].zName;
pFix->zType = zType;
pFix->pName = pName;
@ -182,8 +183,9 @@ int sqliteFixSrcList(
pList->a[i].zDatabase = sqliteStrDup(zDb);
}else if( sqliteStrICmp(pList->a[i].zDatabase,zDb)!=0 ){
sqliteErrorMsg(pFix->pParse,
"%s %.*s cannot reference objects in database %s",
pFix->zType, pFix->pName->n, pFix->pName->z, pList->a[i].zDatabase);
"%s %z cannot reference objects in database %s",
pFix->zType, sqliteStrNDup(pFix->pName->z, pFix->pName->n),
pList->a[i].zDatabase);
return 1;
}
if( sqliteFixSelect(pFix, pList->a[i].pSelect) ) return 1;

View File

@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.190 2003/06/02 23:14:13 drh Exp $
** @(#) $Id: sqliteInt.h,v 1.191 2003/06/03 01:47:11 drh Exp $
*/
#include "config.h"
#include "sqlite.h"
@ -904,7 +904,7 @@ struct Trigger {
IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
the <column-list> is stored here */
int foreach; /* One of TK_ROW or TK_STATEMENT */
Token *pNameToken; /* Token containing zName. Use during parsing only */
Token nameToken; /* Token containing zName. Use during parsing only */
TriggerStep *step_list; /* Link list of trigger program steps */
Trigger *pNext; /* Next trigger associated with the table */

View File

@ -54,6 +54,7 @@ void sqliteBeginTrigger(
char *zName = 0; /* Name of the trigger */
sqlite *db = pParse->db;
int iDb; /* When database to store the trigger in */
DbFixer sFix;
/* Check that:
** 1. the trigger name does not already exist.
@ -64,12 +65,13 @@ void sqliteBeginTrigger(
*/
if( sqlite_malloc_failed ) goto trigger_cleanup;
assert( pTableName->nSrc==1 );
assert( pTableName->a[0].zDatabase==0 );
if( pParse->initFlag ){
pTableName->a[0].zDatabase = db->aDb[pParse->iDb].zName;
if( pParse->initFlag
&& sqliteFixInit(&sFix, pParse, pParse->iDb, "trigger", pName)
&& sqliteFixSrcList(&sFix, pTableName)
){
goto trigger_cleanup;
}
tab = sqliteSrcListLookup(pParse, pTableName);
pTableName->a[0].zDatabase = 0;
if( !tab ){
goto trigger_cleanup;
}
@ -138,7 +140,7 @@ void sqliteBeginTrigger(
nt->pWhen = sqliteExprDup(pWhen);
nt->pColumns = sqliteIdListDup(pColumns);
nt->foreach = foreach;
nt->pNameToken = pName;
sqliteTokenCopy(&nt->nameToken,pName);
assert( pParse->pNewTrigger==0 );
pParse->pNewTrigger = nt;
@ -170,11 +172,10 @@ void sqliteFinishTrigger(
pStepList->pTrig = nt;
pStepList = pStepList->pNext;
}
if( sqliteFixInit(&sFix, pParse, nt->iDb, "trigger", nt->pNameToken)
if( sqliteFixInit(&sFix, pParse, nt->iDb, "trigger", &nt->nameToken)
&& sqliteFixTriggerStep(&sFix, nt->step_list) ){
goto triggerfinish_cleanup;
}
nt->pNameToken = 0;
/* if we are not initializing, and this trigger is not on a TEMP table,
** build the sqlite_master entry
@ -366,6 +367,7 @@ void sqliteDeleteTrigger(Trigger *pTrigger){
sqliteFree(pTrigger->table);
sqliteExprDelete(pTrigger->pWhen);
sqliteIdListDelete(pTrigger->pColumns);
if( pTrigger->nameToken.dyn ) sqliteFree((char*)pTrigger->nameToken.z);
sqliteFree(pTrigger);
}