aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordanielk1977 <danielk1977@noemail.net>2006-01-10 12:31:39 +0000
committerdanielk1977 <danielk1977@noemail.net>2006-01-10 12:31:39 +0000
commiteecfb3eebc14d1bd5ff5ba7e63512be19fc39e0b (patch)
tree48c702ba7db14fad7b3ce30ce75fdb7d0f8cbe7f /src
parent311019be0b70622fd59827ac9419a8f923019e83 (diff)
downloadsqlite-eecfb3eebc14d1bd5ff5ba7e63512be19fc39e0b.tar.gz
sqlite-eecfb3eebc14d1bd5ff5ba7e63512be19fc39e0b.zip
Fix a problem with shared-schemas and temp triggers. (CVS 2901)
FossilOrigin-Name: 9c18a1ce1e7ff6a02eb0f9ce344cab9660819740
Diffstat (limited to 'src')
-rw-r--r--src/sqliteInt.h11
-rw-r--r--src/trigger.c37
2 files changed, 22 insertions, 26 deletions
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 1a6851d32..b9e2ac854 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.457 2006/01/09 23:40:25 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.458 2006/01/10 12:31:40 danielk1977 Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@@ -674,6 +674,8 @@ struct CollSeq {
** is generated for each row of the table. Table.hasPrimKey is true if
** the table has any PRIMARY KEY, INTEGER or otherwise.
**
+** TODO: This comment is out of date. Table.iDb no longer exists.
+**
** Table.tnum is the page number for the root BTree page of the table in the
** database file. If Table.iDb is the index of the database table backend
** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
@@ -694,7 +696,6 @@ struct Table {
int tnum; /* Root BTree node for this table (see note above) */
Select *pSelect; /* NULL for tables. Points to definition if a view. */
u8 readOnly; /* True if this table should not be written by the user */
-// u8 iDb; /* Index into sqlite.aDb[] of the backend for this table */
u8 isTransient; /* True if automatically deleted when VDBE finishes */
u8 hasPrimKey; /* True if there exists a primary key */
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
@@ -806,7 +807,7 @@ struct KeyInfo {
u8 enc; /* Text encoding - one of the TEXT_Utf* values */
u8 incrKey; /* Increase 2nd key by epsilon before comparison */
int nField; /* Number of entries in aColl[] */
- u8 *aSortOrder; /* If defined an aSortOrder[i] is true, sort DESC */
+ u8 *aSortOrder; /* If defined and aSortOrder[i] is true, sort DESC */
CollSeq *aColl[1]; /* Collating sequence for each term of the key */
};
@@ -845,10 +846,9 @@ struct Index {
int tnum; /* Page containing root of this index in database file */
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
- // u8 iDb; /* Index in sqlite.aDb[] of where this index is stored */
char *zColAff; /* String defining the affinity of each column */
Index *pNext; /* The next index associated with the same table */
- Schema *pSchema;
+ Schema *pSchema; /* Schema containing this index */
KeyInfo keyInfo; /* Info on how to order keys. MUST BE LAST */
};
@@ -958,7 +958,6 @@ struct AggInfo {
struct Expr {
u8 op; /* Operation performed by this node */
char affinity; /* The affinity of the column or 0 if not a column */
-//u8 iDb; /* Database referenced by this expression */
u8 flags; /* Various flags. See below */
CollSeq *pColl; /* The collation type of the column or 0 */
Expr *pLeft, *pRight; /* Left and right subnodes */
diff --git a/src/trigger.c b/src/trigger.c
index ec1c4c67a..fbe8951bb 100644
--- a/src/trigger.c
+++ b/src/trigger.c
@@ -740,8 +740,7 @@ int sqlite3CodeRowTrigger(
int orconf, /* ON CONFLICT policy */
int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */
){
- Trigger *pTrigger;
- TriggerStack *pStack;
+ Trigger *p;
TriggerStack trigStackEntry;
assert(op == TK_UPDATE || op == TK_INSERT || op == TK_DELETE);
@@ -749,21 +748,20 @@ int sqlite3CodeRowTrigger(
assert(newIdx != -1 || oldIdx != -1);
- pTrigger = pTab->pTrigger;
- while( pTrigger ){
+ for(p=pTab->pTrigger; p; p=p->pNext){
int fire_this = 0;
- /* determine whether we should code this trigger */
- if( pTrigger->op == op && pTrigger->tr_tm == tr_tm ){
- fire_this = 1;
- for(pStack=pParse->trigStack; pStack; pStack=pStack->pNext){
- if( pStack->pTrigger==pTrigger ){
- fire_this = 0;
- }
- }
- if( op == TK_UPDATE && pTrigger->pColumns &&
- !checkColumnOverLap(pTrigger->pColumns, pChanges) ){
- fire_this = 0;
+ /* Determine whether we should code this trigger */
+ if(
+ p->op==op &&
+ p->tr_tm==tr_tm &&
+ (p->pSchema==p->pTabSchema || p->pSchema==pParse->db->aDb[1].pSchema) &&
+ (op!=TK_UPDATE||!p->pColumns||checkColumnOverLap(p->pColumns,pChanges))
+ ){
+ TriggerStack *pS; /* Pointer to trigger-stack entry */
+ for(pS=pParse->trigStack; pS && p!=pS->pTrigger; pS=pS->pNext);
+ if( !pS ){
+ fire_this = 1;
}
}
@@ -777,18 +775,18 @@ int sqlite3CodeRowTrigger(
sNC.pParse = pParse;
/* Push an entry on to the trigger stack */
- trigStackEntry.pTrigger = pTrigger;
+ trigStackEntry.pTrigger = p;
trigStackEntry.newIdx = newIdx;
trigStackEntry.oldIdx = oldIdx;
trigStackEntry.pTab = pTab;
trigStackEntry.pNext = pParse->trigStack;
trigStackEntry.ignoreJump = ignoreJump;
pParse->trigStack = &trigStackEntry;
- sqlite3AuthContextPush(pParse, &sContext, pTrigger->name);
+ sqlite3AuthContextPush(pParse, &sContext, p->name);
/* code the WHEN clause */
endTrigger = sqlite3VdbeMakeLabel(pParse->pVdbe);
- whenExpr = sqlite3ExprDup(pTrigger->pWhen);
+ whenExpr = sqlite3ExprDup(p->pWhen);
if( sqlite3ExprResolveNames(&sNC, whenExpr) ){
pParse->trigStack = trigStackEntry.pNext;
sqlite3ExprDelete(whenExpr);
@@ -797,7 +795,7 @@ int sqlite3CodeRowTrigger(
sqlite3ExprIfFalse(pParse, whenExpr, endTrigger, 1);
sqlite3ExprDelete(whenExpr);
- codeTriggerProgram(pParse, pTrigger->step_list, orconf);
+ codeTriggerProgram(pParse, p->step_list, orconf);
/* Pop the entry off the trigger stack */
pParse->trigStack = trigStackEntry.pNext;
@@ -805,7 +803,6 @@ int sqlite3CodeRowTrigger(
sqlite3VdbeResolveLabel(pParse->pVdbe, endTrigger);
}
- pTrigger = pTrigger->pNext;
}
return 0;
}