Beginning to clean up the trigger code. Still lots of work to do. (CVS 566)
FossilOrigin-Name: b10346818b25940c6dc85e94de8e36d20954161c
diff --git a/src/build.c b/src/build.c
index c41b1cf..d10c22e 100644
--- a/src/build.c
+++ b/src/build.c
@@ -25,7 +25,7 @@
** ROLLBACK
** PRAGMA
**
-** $Id: build.c,v 1.89 2002/05/15 11:44:14 drh Exp $
+** $Id: build.c,v 1.90 2002/05/15 12:45:43 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -356,7 +356,6 @@
Table * tab = sqliteFindTable(db, pTrigger->table);
sqliteHashInsert(&db->trigHash, pTrigger->name,
strlen(pTrigger->name) + 1, pTrigger);
-
pTrigger->pNext = tab->pTrigger;
tab->pTrigger = pTrigger;
}
@@ -653,7 +652,7 @@
** and the probability of hitting the same cookie value is only
** 1 chance in 2^32. So we're safe enough.
*/
-void changeCookie(sqlite *db){
+void sqliteChangeCookie(sqlite *db){
if( db->next_cookie==db->schema_cookie ){
db->next_cookie = db->schema_cookie + sqliteRandomByte() + 1;
db->flags |= SQLITE_InternChanges;
@@ -852,7 +851,7 @@
}
sqliteVdbeAddOp(v, OP_MakeRecord, 5, 0);
sqliteVdbeAddOp(v, OP_PutIntKey, 0, 0);
- changeCookie(db);
+ sqliteChangeCookie(db);
sqliteVdbeAddOp(v, OP_Integer, db->next_cookie, 0);
sqliteVdbeAddOp(v, OP_SetCookie, 0, 0);
sqliteVdbeAddOp(v, OP_Close, 0, 0);
@@ -1095,7 +1094,7 @@
Index *pIdx;
sqliteBeginWriteOperation(pParse);
/* Drop all triggers associated with the table being dropped */
- while (pTable->pTrigger) {
+ while( pTable->pTrigger ){
Token tt;
tt.z = pTable->pTrigger->name;
tt.n = strlen(pTable->pTrigger->name);
@@ -1104,7 +1103,7 @@
if( !pTable->isTemp ){
base = sqliteVdbeAddOpList(v, ArraySize(dropTable), dropTable);
sqliteVdbeChangeP3(v, base+2, pTable->zName, 0);
- changeCookie(db);
+ sqliteChangeCookie(db);
sqliteVdbeChangeP1(v, base+9, db->next_cookie);
}
if( !isView ){
@@ -1409,7 +1408,7 @@
}
if( pTable!=0 ){
if( !isTemp ){
- changeCookie(db);
+ sqliteChangeCookie(db);
sqliteVdbeAddOp(v, OP_Integer, db->next_cookie, 0);
sqliteVdbeAddOp(v, OP_SetCookie, 0, 0);
sqliteVdbeAddOp(v, OP_Close, 0, 0);
@@ -1472,7 +1471,7 @@
if( !pTab->isTemp ){
base = sqliteVdbeAddOpList(v, ArraySize(dropIndex), dropIndex);
sqliteVdbeChangeP3(v, base+2, pIndex->zName, P3_STATIC);
- changeCookie(db);
+ sqliteChangeCookie(db);
sqliteVdbeChangeP1(v, base+10, db->next_cookie);
}
sqliteVdbeAddOp(v, OP_Destroy, pIndex->tnum, pTab->isTemp);
@@ -1711,14 +1710,14 @@
** Generate VDBE code that prepares for doing an operation that
** might change the database. The operation will be atomic in the
** sense that it will either do its changes completely or not at
-** all. So there is not need to set a checkpoint is a transaction
+** all. So there is no need to set a checkpoint is a transaction
** is already in effect.
*/
void sqliteBeginWriteOperation(Parse *pParse){
Vdbe *v;
v = sqliteGetVdbe(pParse);
if( v==0 ) return;
- if (pParse->trigStack) return; /* if this is in a trigger */
+ if( pParse->trigStack ) return; /* if this is in a trigger */
if( (pParse->db->flags & SQLITE_InTrans)==0 ){
sqliteVdbeAddOp(v, OP_Transaction, 0, 0);
sqliteVdbeAddOp(v, OP_VerifyCookie, pParse->db->schema_cookie, 0);
@@ -1738,7 +1737,7 @@
Vdbe *v;
v = sqliteGetVdbe(pParse);
if( v==0 ) return;
- if (pParse->trigStack) return; /* if this is in a trigger */
+ if( pParse->trigStack ) return; /* if this is in a trigger */
if( (pParse->db->flags & SQLITE_InTrans)==0 ){
sqliteVdbeAddOp(v, OP_Transaction, 0, 0);
sqliteVdbeAddOp(v, OP_VerifyCookie, pParse->db->schema_cookie, 0);
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 7354050..e48366f 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.108 2002/05/15 08:30:14 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.109 2002/05/15 12:45:43 drh Exp $
*/
#include "sqlite.h"
#include "hash.h"
@@ -558,63 +558,49 @@
** while generating expressions. Normally false */
int schemaVerified; /* True if an OP_VerifySchema has been coded someplace
** other than after an OP_Transaction */
-
- TriggerStack * trigStack;
+ TriggerStack *trigStack;
};
struct TriggerStack {
- Trigger * pTrigger;
- Table * pTab; /* Table that triggers are currently being coded as */
- int newIdx; /* Index of "new" temp table */
- int oldIdx; /* Index of "old" temp table */
- int orconf; /* Current orconf policy */
- struct TriggerStack * pNext;
+ Trigger *pTrigger;
+ Table *pTab; /* Table that triggers are currently being coded as */
+ int newIdx; /* Index of "new" temp table */
+ int oldIdx; /* Index of "old" temp table */
+ int orconf; /* Current orconf policy */
+ TriggerStack *pNext;
};
struct TriggerStep {
int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
int orconf;
- Select * pSelect; /* Valid for SELECT and sometimes
+ Select *pSelect; /* Valid for SELECT and sometimes
INSERT steps (when pExprList == 0) */
Token target; /* Valid for DELETE, UPDATE, INSERT steps */
- Expr * pWhere; /* Valid for DELETE, UPDATE steps */
- ExprList * pExprList; /* Valid for UPDATE statements and sometimes
+ Expr *pWhere; /* Valid for DELETE, UPDATE steps */
+ ExprList *pExprList; /* Valid for UPDATE statements and sometimes
INSERT steps (when pSelect == 0) */
IdList *pIdList; /* Valid for INSERT statements only */
TriggerStep * pNext; /* Next in the link-list */
};
struct Trigger {
- char * name; /* The name of the trigger */
- char * table; /* The table or view to which the trigger applies */
- int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
- int tr_tm; /* One of TK_BEFORE, TK_AFTER, TK_INSTEAD */
- Expr * pWhen; /* The WHEN clause of the expresion (may be NULL) */
- IdList * pColumns; /* If this is an UPDATE OF <column-list> trigger,
- the column names are stored in this list */
- int foreach; /* One of TK_ROW or TK_STATEMENT */
+ char *name; /* The name of the trigger */
+ char *table; /* The table or view to which the trigger applies */
+ int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
+ int tr_tm; /* One of TK_BEFORE, TK_AFTER, TK_INSTEAD */
+ Expr *pWhen; /* The WHEN clause of the expresion (may be NULL) */
+ IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
+ the column names are stored in this list */
+ int foreach; /* One of TK_ROW or TK_STATEMENT */
- TriggerStep * step_list; /* Link list of trigger program steps */
-
- char * strings; /* pointer to the allocation of Token strings */
- Trigger * pNext; /* Next trigger associated with the table */
+ TriggerStep *step_list; /* Link list of trigger program steps */
+ char *strings; /* pointer to allocation of Token strings */
+ Trigger *pNext; /* Next trigger associated with the table */
int isCommit;
};
-TriggerStep * sqliteTriggerSelectStep(Select *);
-TriggerStep * sqliteTriggerInsertStep(Token *, IdList *, ExprList *,
- Select *, int);
-TriggerStep * sqliteTriggerUpdateStep(Token *, ExprList *, Expr *, int);
-TriggerStep * sqliteTriggerDeleteStep(Token *, Expr *);
-
extern int always_code_trigger_setup;
-void sqliteCreateTrigger(Parse * ,Token *, int, int, IdList *, Token *, int, Expr *, TriggerStep *, char const *,int);
-void sqliteDropTrigger(Parse *, Token *, int);
-int sqliteTriggersExist( Parse * , Trigger * , int , int , int, ExprList * );
-int sqliteCodeRowTrigger( Parse * pParse, int op, ExprList *, int tr_tm, Table * tbl, int newTable, int oldTable, int onError);
-
-void sqliteViewTriggers(Parse *, Table *, Expr *, int, ExprList *);
/*
** Internal function prototypes
@@ -726,5 +712,14 @@
int sqliteSafetyOn(sqlite*);
int sqliteSafetyOff(sqlite*);
int sqliteSafetyCheck(sqlite*);
-
-void changeCookie(sqlite *);
+void sqliteChangeCookie(sqlite *);
+void sqliteCreateTrigger(Parse*, Token*, int, int, IdList*, Token*,
+ int, Expr*, TriggerStep*, char const*,int);
+void sqliteDropTrigger(Parse*, Token*, int);
+int sqliteTriggersExist(Parse* , Trigger* , int , int , int, ExprList*);
+int sqliteCodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int, int);
+void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
+TriggerStep *sqliteTriggerSelectStep(Select*);
+TriggerStep *sqliteTriggerInsertStep(Token*, IdList*, ExprList*, Select*, int);
+TriggerStep *sqliteTriggerUpdateStep(Token*, ExprList*, Expr*, int);
+TriggerStep *sqliteTriggerDeleteStep(Token*, Expr*);
diff --git a/src/trigger.c b/src/trigger.c
index 044ef25..e4c78bf 100644
--- a/src/trigger.c
+++ b/src/trigger.c
@@ -102,7 +102,7 @@
sqliteVdbeAddOp(pParse->pVdbe, OP_PutIntKey, 0, 1);
/* Change the cookie, since the schema is changed */
- changeCookie(pParse->db);
+ sqliteChangeCookie(pParse->db);
sqliteVdbeAddOp(pParse->pVdbe, OP_Integer, pParse->db->next_cookie, 0);
sqliteVdbeAddOp(pParse->pVdbe, OP_SetCookie, 0, 0);
@@ -300,20 +300,19 @@
{ OP_Close, 0, 0, 0},
};
- if (!nested)
+ if( !nested ){
sqliteBeginWriteOperation(pParse);
-
+ }
base = sqliteVdbeAddOpList(pParse->pVdbe,
ArraySize(dropTrigger), dropTrigger);
sqliteVdbeChangeP3(pParse->pVdbe, base+2, tmp_name, 0);
-
- if (!nested)
- changeCookie(pParse->db);
-
+ if( !nested ){
+ sqliteChangeCookie(pParse->db);
+ }
sqliteVdbeChangeP1(pParse->pVdbe, base+9, pParse->db->next_cookie);
-
- if (!nested)
+ if( !nested ){
sqliteEndWriteOperation(pParse);
+ }
}
sqliteFree(tmp_name);