]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Beginning to clean up the trigger code. Still lots of work to do. (CVS 566)
authordrh <drh@noemail.net>
Wed, 15 May 2002 12:45:43 +0000 (12:45 +0000)
committerdrh <drh@noemail.net>
Wed, 15 May 2002 12:45:43 +0000 (12:45 +0000)
FossilOrigin-Name: b10346818b25940c6dc85e94de8e36d20954161c

Makefile.template
manifest
manifest.uuid
src/build.c
src/sqliteInt.h
src/trigger.c

index 9f2b5edbd9bfe90eb4acd0a368d60820fc04c20b..99c9451fdbdd304a5e78487b755b5075cfb50a7d 100644 (file)
@@ -118,7 +118,7 @@ TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
 #
 LIBOBJ = btree.o build.o delete.o expr.o func.o hash.o insert.o \
          main.o os.o pager.o parse.o printf.o random.o select.o table.o \
-         tokenize.o update.o util.o vdbe.o where.o tclsqlite.o
+         tokenize.o trigger.o update.o util.o vdbe.o where.o tclsqlite.o
 
 # All of the source code files.
 #
@@ -146,6 +146,7 @@ SRC = \
   $(TOP)/src/table.c \
   $(TOP)/src/tclsqlite.c \
   $(TOP)/src/tokenize.c \
+  $(TOP)/src/trigger.c \
   $(TOP)/src/update.c \
   $(TOP)/src/util.c \
   $(TOP)/src/vdbe.c \
@@ -245,6 +246,9 @@ sqlite.h:   $(TOP)/src/sqlite.h.in
 tokenize.o:    $(TOP)/src/tokenize.c $(HDR)
        $(TCCX) -c $(TOP)/src/tokenize.c
 
+trigger.o:     $(TOP)/src/trigger.c $(HDR)
+       $(TCCX) -c $(TOP)/src/trigger.c
+
 util.o:        $(TOP)/src/util.c $(HDR)
        $(TCCX) -c $(TOP)/src/util.c
 
index 1926204ddd6f00e28757a1420c0560d5ad87f0de..8dcb6035d1af2d2ae10fc09bf6da75b13dd279ee 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,7 +1,7 @@
-C Remove\sall\stabs\sfrom\sthe\sbeginning\sof\ssource\scode\slines.\s\sReplace\stabs\swith\nthe\sappropriate\snumber\sof\sspaces.\s(CVS\s565)
-D 2002-05-15T11:44:14
+C Beginning\sto\sclean\sup\sthe\strigger\scode.\s\sStill\slots\sof\swork\sto\sdo.\s(CVS\s566)
+D 2002-05-15T12:45:43
 F Makefile.in 6291a33b87d2a395aafd7646ee1ed562c6f2c28c
-F Makefile.template 89e373b2dad0321df00400fa968dc14b61a03296
+F Makefile.template 4e11752e0b5c7a043ca50af4296ec562857ba495
 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
 F VERSION 45e2ae5cf63867a750b544c539f79a076d53a9a0
 F aclocal.m4 11faa843caa38fd451bc6aeb43e248d1723a269d
@@ -20,7 +20,7 @@ F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
 F src/TODO af7f3cab0228e34149cf98e073aa83d45878e7e6
 F src/btree.c c01b404b9373ae1c0daf7d1f9211c72ead67638e
 F src/btree.h 8abeabfe6e0b1a990b64fa457592a6482f6674f3
-F src/build.c 74f19f9001ee3708b451faf8fc8a6b36024a9be7
+F src/build.c 705ebd993ac708bb3d04f4b9019d42dc205408cc
 F src/delete.c 48e4c533b39d6edfcfca23fb500129b80b7cad30
 F src/encode.c 346b12b46148506c32038524b95c4631ab46d760
 F src/expr.c 6888e37e4eecdc20567aedd442328df752465723
@@ -41,7 +41,7 @@ F src/select.c 1b623a7d826ec7c245bc542b665d61724da2a62d
 F src/shell.c 5acbe59e137d60d8efd975c683dbea74ab626530
 F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
 F src/sqlite.h.in 0038faa6d642de06b91143ee65a131bd831d020b
-F src/sqliteInt.h a96603825503c5bbd095f1ac34ce1023f89a908e
+F src/sqliteInt.h 26f8cefb76e9393413ac22468c8dd0ed41abf67c
 F src/table.c eed2098c9b577aa17f8abe89313a9c4413f57d63
 F src/tclsqlite.c 9300c9606a38bc0c75d6c0bc8a6197ab979353d1
 F src/test1.c 09d95048b66ce6dcd2bae90f443589043d7d631e
@@ -49,7 +49,7 @@ F src/test2.c 669cc22781c6461a273416ec1a7414d25c081730
 F src/test3.c 4e52fff8b01f08bd202f7633feda5639b7ba2b5e
 F src/threadtest.c 81f0598e0f031c1bd506af337fdc1b7e8dff263f
 F src/tokenize.c f12f78c58b2a79ea4eee880efad63a328e103c62
-F src/trigger.c 768b895cf09382db4e2d1ce5aace7e6a4cbf7e4d
+F src/trigger.c 491d5d3b40d737365a1ade7d4039277991208dc3
 F src/update.c f9b53d46cc651b9630fc53342b9e792031f6fc5c
 F src/util.c 707c30f8c13cddace7c08556ac450c0b786660b3
 F src/vdbe.c 42281b4e0e0c4a089018a14d6840ada5a1896e51
@@ -134,7 +134,7 @@ F www/speed.tcl da8afcc1d3ccc5696cfb388a68982bc3d9f7f00f
 F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P d1d8642b57bd0765ade730248012d58b0859c12c
-R 7c8b29631adcec690efa7e7338377d43
+P 690f9a163173c4c7af7e8e92e942cee4184c7974
+R 2c7fa77b8b0294150616cb3ad535e3be
 U drh
-Z 13f7f043962d157cad884aca33ba63e6
+Z 2f79a3bdfbaced77f180a80585eae438
index e890d55f07eba62ca324749e34b243e1477d62e6..d6e41fb42830d4b695bfea1455e0ebaa419a0bfa 100644 (file)
@@ -1 +1 @@
-690f9a163173c4c7af7e8e92e942cee4184c7974
\ No newline at end of file
+b10346818b25940c6dc85e94de8e36d20954161c
\ No newline at end of file
index c41b1cf0361366cd251489008f3e69aac899e36a..d10c22ec73ebbfe3896c4e1412e8e377a97b21be 100644 (file)
@@ -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 @@ void sqliteRollbackInternalChanges(sqlite *db){
     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 @@ void sqliteAddPrimaryKey(Parse *pParse, IdList *pList, int onError){
 ** 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 @@ void sqliteEndTable(Parse *pParse, Token *pEnd, Select *pSelect){
       }
       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 @@ void sqliteDropTable(Parse *pParse, Token *pName, int isView){
     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 @@ void sqliteDropTable(Parse *pParse, Token *pName, int isView){
     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 @@ void sqliteCreateIndex(
     }
     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 @@ void sqliteDropIndex(Parse *pParse, Token *pName){
     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 @@ void sqliteRollbackTransaction(Parse *pParse){
 ** 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 @@ void sqliteBeginMultiWriteOperation(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);
index 7354050a1438d012abde1f82816dd1ba593200a9..e48366f74695be6b1366d86758f4eb451944bba7 100644 (file)
@@ -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 @@ 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;
+  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 */
-
-  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 */
+  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 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 @@ void sqliteRegisterBuildinFunctions(sqlite*);
 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*);
index 044ef254d42a810550e257a0d79dca8df4bb54a7..e4c78bf386ace29f63f8fa3abd1eb2bbc62342de 100644 (file)
@@ -102,7 +102,7 @@ void sqliteCreateTrigger(
     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 @@ void sqliteDropTrigger(Parse *pParse, Token * trigname, int nested)
       { 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);