diff options
author | drh <drh@noemail.net> | 2003-04-17 22:57:53 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2003-04-17 22:57:53 +0000 |
commit | a69d91681d1fc36f40aa6602413d7db673c20992 (patch) | |
tree | c3e975c61c7cef5d928809fe69a5e8a515d815bf /src/build.c | |
parent | d4d595f94c3c02d90872d90ec5bb43cf11426abc (diff) | |
download | sqlite-a69d91681d1fc36f40aa6602413d7db673c20992.tar.gz sqlite-a69d91681d1fc36f40aa6602413d7db673c20992.zip |
Fix triggers to work in an ATTACHed database. Ticket #295. (CVS 915)
FossilOrigin-Name: 1e5e00fb73c308378efd034cb291caf338c9fe84
Diffstat (limited to 'src/build.c')
-rw-r--r-- | src/build.c | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/src/build.c b/src/build.c index 6db409278..44c482732 100644 --- a/src/build.c +++ b/src/build.c @@ -23,7 +23,7 @@ ** ROLLBACK ** PRAGMA ** -** $Id: build.c,v 1.145 2003/04/15 01:19:48 drh Exp $ +** $Id: build.c,v 1.146 2003/04/17 22:57:53 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -109,7 +109,10 @@ void sqliteExec(Parse *pParse){ /* ** Locate the in-memory structure that describes ** a particular database table given the name -** of that table. Return NULL if not found. +** of that table and (optionally) the name of the database +** containing the table. Return NULL if not found. +** +** See also sqliteLocateTable(). */ Table *sqliteFindTable(sqlite *db, const char *zName, const char *zDatabase){ Table *p = 0; @@ -125,7 +128,48 @@ Table *sqliteFindTable(sqlite *db, const char *zName, const char *zDatabase){ /* ** Locate the in-memory structure that describes -** a particular index given the name of that index. +** a particular database table given the name +** of that table and (optionally) the name of the database +** containing the table. Return NULL if not found. +** +** If pParse->useDb is not negative, then the table must be +** located in that database. If a different database is specified, +** an error message is generated into pParse->zErrMsg. +*/ +Table *sqliteLocateTable(Parse *pParse, const char *zName, const char *zDbase){ + sqlite *db; + const char *zUse; + Table *p; + db = pParse->db; + if( pParse->useDb<0 ){ + p = sqliteFindTable(db, zName, zDbase); + }else { + assert( pParse->useDb<db->nDb ); + assert( db->aDb[pParse->useDb].pBt!=0 ); + zUse = db->aDb[pParse->useDb].zName; + if( zDbase && pParse->useDb!=1 && sqliteStrICmp(zDbase, zUse)!=0 ){ + sqliteErrorMsg(pParse,"cannot use database %s in this context", zDbase); + return 0; + } + p = sqliteFindTable(db, zName, zUse); + if( p==0 && pParse->useDb==1 && zDbase==0 ){ + p = sqliteFindTable(db, zName, 0); + } + } + if( p==0 ){ + if( zDbase ){ + sqliteErrorMsg(pParse, "no such table: %s.%s", zDbase, zName); + }else{ + sqliteErrorMsg(pParse, "no such table: %s", zName); + } + } + return p; +} + +/* +** Locate the in-memory structure that describes +** a particular index given the name of that index +** and the name of the database that contains the index. ** Return NULL if not found. */ Index *sqliteFindIndex(sqlite *db, const char *zName, const char *zDb){ @@ -2078,7 +2122,13 @@ void sqliteBeginWriteOperation(Parse *pParse, int setCheckpoint, int tempOnly){ if( (pParse->db->flags & SQLITE_InTrans)==0 ){ sqliteVdbeAddOp(v, OP_Transaction, 1, 0); if( !tempOnly ){ + int i; + sqlite *db = pParse->db; sqliteVdbeAddOp(v, OP_Transaction, 0, 0); + for(i=2; i<db->nDb; i++){ + if( db->aDb[i].pBt==0 ) continue; + sqliteVdbeAddOp(v, OP_Transaction, i, 0); + } sqliteCodeVerifySchema(pParse); } }else if( setCheckpoint ){ |