1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Added FOR EACH ROW triggers functionality (CVS 562)

FossilOrigin-Name: 794bf67b6b36fce8854d5daff12f21dbb943240c
This commit is contained in:
danielk1977
2002-05-15 08:30:12 +00:00
parent 9456bcc975
commit c3f9bad209
18 changed files with 2239 additions and 125 deletions

View File

@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.107 2002/05/10 13:14:07 drh Exp $
** @(#) $Id: sqliteInt.h,v 1.108 2002/05/15 08:30:14 danielk1977 Exp $
*/
#include "sqlite.h"
#include "hash.h"
@@ -144,6 +144,9 @@ typedef struct WhereLevel WhereLevel;
typedef struct Select Select;
typedef struct AggExpr AggExpr;
typedef struct FuncDef FuncDef;
typedef struct Trigger Trigger;
typedef struct TriggerStep TriggerStep;
typedef struct TriggerStack TriggerStack;
/*
** Each database is an instance of the following structure
@@ -170,6 +173,9 @@ struct sqlite {
int magic; /* Magic number for detect library misuse */
int nChange; /* Number of rows changed */
int recursionDepth; /* Number of nested calls to sqlite_exec() */
Hash trigHash; /* All triggers indexed by name */
Hash trigDrop; /* Uncommited dropped triggers */
};
/*
@@ -270,6 +276,8 @@ struct 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 */
Trigger *pTrigger; /* List of SQL triggers on this table */
};
/*
@@ -550,8 +558,64 @@ struct Parse {
** while generating expressions. Normally false */
int schemaVerified; /* True if an OP_VerifySchema has been coded someplace
** other than after an OP_Transaction */
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;
};
struct TriggerStep {
int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
int orconf;
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
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 */
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 */
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
*/
@@ -662,3 +726,5 @@ void sqliteRegisterBuildinFunctions(sqlite*);
int sqliteSafetyOn(sqlite*);
int sqliteSafetyOff(sqlite*);
int sqliteSafetyCheck(sqlite*);
void changeCookie(sqlite *);