Lines Matching defs:Trigger
284 ** A value of 1 means that a trigger program will not be able to itself
285 ** fire any triggers. A value of 0 means that no trigger programs at all
2172 ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
2179 ** which case the trigger setting is not reported back. </dd>
2214 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
2216 ** row as long as the trigger or virtual table method is running.
2217 ** But once the trigger or virtual table method ends, the value returned
2218 ** by this routine reverts to what it was before the trigger or virtual
2258 ** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
2267 ** A "trigger context" is a scope of execution that begins and
2268 ** ends with the script of a [CREATE TRIGGER | trigger].
2270 ** evaluated outside of any trigger. This is the "top level"
2271 ** trigger context. If a trigger fires from the top level, a
2272 ** new trigger context is entered for the duration of that one
2273 ** trigger. Subtriggers create subcontexts for their duration.
2276 ** not create a new trigger context.
2280 ** trigger context.
2284 ** that also occurred at the top level. ^(Within the body of a trigger,
2287 ** statement within the body of the same trigger.
2306 ** from all [CREATE TRIGGER | trigger] contexts and changes made by
2310 ** count does not include rows of views that fire an [INSTEAD OF trigger],
2311 ** though if the INSTEAD OF trigger makes changes of its own, those changes
2374 ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
2904 ** is the name of the inner-most trigger or view that is responsible for
2913 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
2915 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
2922 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
2924 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
2955 ** contain a UTF-8 SQL comment that identifies the trigger.)^
8157 typedef struct Trigger Trigger;
8497 ** A sub-routine used to implement a trigger program.
9742 u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
10199 Trigger *pTrigger; /* List of triggers stored in pSchema */
10256 Trigger *apTrigger[2]; /* Triggers for aAction[] actions */
10690 ** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
11034 ** trigger that may be fired while parsing an INSERT, UPDATE or DELETE
11039 ** A Vdbe sub-program that implements the body and WHEN clause of trigger
11051 Trigger *pTrigger; /* Trigger this program was coded from */
11129 /* Information used while coding trigger programs. */
11136 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
11160 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
11201 * Each trigger present in the database schema is stored as an instance of
11202 * struct Trigger.
11204 * Pointers to instances of struct Trigger are stored in two ways.
11206 * database). This allows Trigger structures to be retrieved by name.
11208 * pNext member of struct Trigger. A pointer to the first element of the
11213 * containing the SQL statements specified as the trigger program.
11215 struct Trigger {
11216 char *zName; /* The name of the trigger */
11217 char *table; /* The table or view to which the trigger applies */
11221 IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
11223 Schema *pSchema; /* Schema containing the trigger */
11225 TriggerStep *step_list; /* Link list of trigger program steps */
11226 Trigger *pNext; /* Next trigger associated with the table */
11230 ** A trigger is either a BEFORE or an AFTER trigger. The following constants
11241 * that is a part of a trigger-program.
11245 * associated struct Trigger instance. The first element of the linked list is
11246 * the first step of the trigger-program.
11280 Trigger *pTrig; /* The trigger that this step is a part of */
11732 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int, Trigger *, int);
11766 SQLITE_PRIVATE void sqlite3DropTriggerPtr(Parse*, Trigger*);
11767 SQLITE_PRIVATE Trigger *sqlite3TriggersExist(Parse *, Table*, int, ExprList*, int *pMask);
11768 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *, Table *);
11769 SQLITE_PRIVATE void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, int, Table *,
11771 SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, int, int, int);
11779 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3*, Trigger*);
11781 SQLITE_PRIVATE u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int);
13472 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
18825 ** Trigger the alarm
60670 ** the trigger subprograms are listed one by one.
60705 ** the sum of the number of rows in all trigger subprograms encountered
60706 ** so far. The nRow value will increase as new trigger subprograms are
60713 ** to trigger subprograms. The VDBE is guaranteed to have at least 9
61137 ** is used, for example, when a trigger sub-program is halted to restore
65357 void *t; /* Token identifying trigger */
69052 ** This is used by trigger programs.
69868 ** the trigger named P4 in database P1. This is called after a trigger
70050 ** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
70059 ** P4 is a pointer to the VM containing the trigger program.
70070 void *t; /* Token identifying trigger */
70079 ** is really a trigger, not a foreign key action, and the flag set
70083 ** disabled. In some cases a single trigger may generate more than one
70084 ** SubProgram (if the trigger may be executed with more than one different
70086 ** single trigger all have the same value for the SubProgram.token
70096 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
70102 ** the trigger program. If this trigger has been fired before, then u.cc.pRt
70174 ** address space. This is used by trigger programs to access the new.*
73435 ** it is a new.* or old.* trigger argument reference
74325 ** Y: The name of a table in a FROM clause. Or in a trigger
76037 ** * We are inside a trigger
77135 ** trigger programs. In this case Expr.iTable is set to 1 for the
77282 "RAISE() may only be used within a trigger-program");
77568 ** trigger programs. In this case Expr.iTable is set to 1 for the
78618 ** ALTER TABLE command. The first argument is the text of a CREATE TRIGGER
78620 ** TRIGGER statement is replaced with the third argument and the result
78622 ** TRIGGER, not CREATE INDEX and CREATE TABLE.
78642 /* The principle used to locate the table name in the CREATE TRIGGER
78675 ** "CREATE TRIGGER ... ON ON.ON BEGIN ..." etc.
78684 ** in the CREATE TRIGGER statement.
78766 Trigger *pTrig;
78771 ** returned, loop through the tables list of triggers. For each trigger
78784 char *zNew = sqlite3MPrintf(pParse->db, "type='trigger' AND (%s)", zWhere);
78804 Trigger *pTrig;
78825 /* Reload the table, index and permanent trigger schemas. */
78991 "WHEN type = 'trigger' THEN sqlite_rename_trigger(sql, %Q)"
79001 "(type='table' OR type='index' OR type='trigger');",
80849 const char *zType, /* "view", "trigger", or "index" */
80850 const Token *pName /* Name of the view, trigger, or index */
80870 ** These routines are used to make sure that an index, trigger, or
80963 TriggerStep *pStep /* The trigger step be fixed to one database */
81108 ** is in pTabList or else it is the NEW or OLD table of a trigger.
81874 /* The table or view or trigger name is passed to this routine via tokens
81923 ** trigger). All names are legal except those that begin with the string
83244 Trigger *pTrigger;
83286 ** dropped. Triggers are handled seperately because a trigger can be
83291 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
85467 sqlite3DeleteTrigger(0, (Trigger*)sqliteHashData(pElem));
85751 Trigger *pTrigger; /* List of table triggers, if required */
85993 Trigger *pTrigger, /* List of triggers to (potentially) fire */
86004 ** (this can happen if a trigger program has already deleted it), do
86033 /* Invoke BEFORE DELETE trigger programs. */
86066 /* Invoke AFTER DELETE trigger programs. */
86072 ** trigger programs were invoked. Or if a trigger program throws a
88376 ** The second argument is a Trigger structure allocated by the
88377 ** fkActionTrigger() routine. This function deletes the Trigger structure
88380 ** The Trigger structure or any of its sub-components may be allocated from
88383 static void fkTriggerDelete(sqlite3 *dbMem, Trigger *p){
88617 ** deferred trigger. That's what RESTRICT means. To defer checking
88724 ** It returns a pointer to a Trigger structure containing a trigger
88736 ** then the returned trigger structure is equivalent to:
88738 ** CREATE TRIGGER ... DELETE ON p BEGIN
88746 static Trigger *fkActionTrigger(
88754 Trigger *pTrigger; /* Trigger definition to return */
88766 TriggerStep *pStep = 0; /* First (only) step of trigger program */
88767 Expr *pWhere = 0; /* WHERE clause of trigger step */
88771 Expr *pWhen = 0; /* WHEN clause for the trigger */
88873 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
88874 sizeof(Trigger) + /* struct Trigger */
88875 sizeof(TriggerStep) + /* Single step in trigger program */
88941 ** trigger sub-program. */
88945 Trigger *pAction = fkActionTrigger(pParse, pTab, pFKey, pChanges);
89229 /* This routine is never called during trigger-generation. It is
89474 Trigger *pTrigger; /* List of triggers on pTab, if required */
89475 int tmask; /* Mask of trigger times */
89813 ** translated into a unique ID for the row. But on a BEFORE trigger,
89858 /* If this is an INSERT on a view with an INSTEAD OF INSERT trigger,
90281 Trigger *pTrigger = 0;
90392 Trigger *pTrigger = 0;
92298 /* This flag may only be set if both foreign-key and trigger support
93721 ** argv[1] = root page number for table or index. 0 for trigger or view.
95260 ** the body of a TRIGGER. The purpose of such selects is to call
95577 /* At one time, code such as "SELECT new.x" within a trigger would
95579 ** trigger code is generated and so this condition is no longer
98408 ** a trigger, then we only need to compute the value of the subquery
99351 /************** Begin file trigger.c *****************************************/
99385 ** the table. The list is connected by Trigger.pNext pointers.
99397 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
99399 Trigger *pList = 0; /* List of triggers to return */
99409 Trigger *pTrig = (Trigger *)sqliteHashData(p);
99423 ** This is called by the parser when it sees a CREATE TRIGGER statement
99424 ** up to the point of the BEGIN before the trigger actions. A Trigger
99426 ** in pParse->pNewTrigger. After the trigger actions have been parsed, the
99427 ** sqlite3FinishTrigger() function is called to complete the trigger
99431 Parse *pParse, /* The parse context of the CREATE TRIGGER statement */
99432 Token *pName1, /* The name of the trigger */
99433 Token *pName2, /* The name of the trigger */
99436 IdList *pColumns, /* column list if this is an UPDATE OF trigger */
99437 SrcList *pTableName,/* The name of the table/view the trigger applies to */
99440 int noErr /* Suppress errors if the trigger already exists */
99442 Trigger *pTrigger = 0; /* The new trigger */
99443 Table *pTab; /* Table that the trigger fires off of */
99444 char *zName = 0; /* Name of the trigger */
99446 int iDb; /* The database to store the trigger in */
99456 /* If TEMP was specified, then the trigger name may not be qualified. */
99458 sqlite3ErrorMsg(pParse, "temporary trigger may not have qualified name");
99464 /* Figure out the db that the the trigger will be created in */
99476 ** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
99487 /* If the trigger name was unqualified, and the table is a temp table,
99488 ** then set iDb to 1 to create the trigger in the temporary database.
99501 trigger", pName) &&
99511 ** dropped too. But if a TEMP trigger is created on a non-TEMP table
99513 ** trigger is not visible to the database connection that does the
99514 ** drop so the trigger cannot be dropped. This results in an
99515 ** "orphaned trigger" - a trigger whose associated table is missing.
99526 /* Check that the trigger name is not reserved and that no trigger of the
99536 sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
99544 /* Do not create a trigger on a system table */
99546 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
99555 sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
99561 " trigger on table: %S", pTableName, 0);
99583 ** INSTEAD OF trigger into a BEFORE trigger. It simplifies code
99590 /* Build the Trigger object */
99591 pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
99618 ** This routine is called after all of the trigger actions have been parsed
99619 ** in order to complete the process of building the trigger.
99624 Token *pAll /* Token that describes the complete CREATE TRIGGER */
99626 Trigger *pTrig = pParse->pNewTrigger; /* Trigger being finished */
99627 char *zName; /* Name of trigger */
99630 int iDb; /* Database containing the trigger */
99631 Token nameToken; /* Trigger name for error reporting */
99644 if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken)
99662 "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
99668 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
99672 Trigger *pLink = pTrig;
99696 ** a trigger step. Return a pointer to a TriggerStep structure.
99699 ** body of a TRIGGER.
99714 ** Allocate space to hold a new trigger step. The allocated space
99721 u8 op, /* Trigger opcode */
99738 ** Build a trigger step out of an INSERT statement. Return a pointer
99739 ** to the new trigger step.
99742 ** body of a trigger.
99773 ** Construct a trigger step that implements an UPDATE statement and return
99774 ** a pointer to that trigger step. The parser calls this routine when it
99775 ** sees an UPDATE statement inside the body of a CREATE TRIGGER.
99798 ** Construct a trigger step that implements a DELETE statement and return
99799 ** a pointer to that trigger step. The parser calls this routine when it
99800 ** sees a DELETE statement inside the body of a CREATE TRIGGER.
99819 ** Recursively delete a Trigger structure
99821 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *db, Trigger *pTrigger){
99832 ** This function is called to drop a trigger from the database schema.
99835 ** the trigger by name. The sqlite3DropTriggerPtr() routine does the
99836 ** same job as this routine except it takes a pointer to the trigger
99837 ** instead of the trigger name.
99840 Trigger *pTrigger = 0;
99866 sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);
99880 ** Return a pointer to the Table structure for the table that a trigger
99883 static Table *tableOfTrigger(Trigger *pTrigger){
99890 ** Drop a trigger given a pointer to that trigger.
99892 SQLITE_PRIVATE void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger){
99916 /* Generate code to destroy the database record of the trigger.
99926 { OP_String8, 0, 1, 0}, /* 4: "trigger" */
99937 sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
99948 ** Remove a trigger from the hash tables of the sqlite* pointer.
99951 Trigger *pTrigger;
99960 Trigger **pp;
99989 ** one trigger that must be fired when an operation of type 'op' is
99993 SQLITE_PRIVATE Trigger *sqlite3TriggersExist(
100001 Trigger *pList = 0;
100002 Trigger *p;
100024 ** forming the SrcList. This prevents a trigger in one database from
100026 ** trigger is in TEMP in which case it can refer to any other database it
100031 TriggerStep *pStep /* The trigger containing the target token */
100052 ** trigger.
100056 TriggerStep *pStepList, /* List of statements inside the trigger body */
100068 ** of the trigger program. If the statement that caused this trigger
100070 ** the ON CONFLICT policy that was specified as part of the trigger
100073 ** CREATE TRIGGER AFTER INSERT ON t1 BEGIN;
100146 ** (trigger program). If an error has occurred, transfer error information
100162 ** implementing trigger pTrigger with ON CONFLICT policy orconf.
100166 Trigger *pTrigger, /* Trigger to code */
100168 int orconf /* ON CONFLICT policy to code trigger program with */
100173 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
100176 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
100199 ** trigger sub-program. */
100223 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
100241 /* Code the trigger program into the sub-vdbe. */
100273 ** trigger pTrigger with default ON CONFLICT algorithm orconf. If no such
100279 Trigger *pTrigger, /* Trigger to code */
100280 Table *pTab, /* The table trigger pTrigger is attached to */
100288 /* It may be that this trigger has already been coded (or is in the
100306 ** Generate code for the trigger program associated with trigger p on
100313 Trigger *p, /* Trigger to code */
100325 ** is a pointer to the sub-vdbe containing the trigger program. */
100335 ** recursive invocation of this trigger program is disallowed. Recursive
100336 ** invocation is disallowed if (a) the sub-program is really a trigger,
100355 ** in the trigger program. If N is the number of columns in table pTab
100370 ** never be accessed by the trigger program, so they are not allocated or
100374 ** ON INSERT trigger, the value passed to this function as parameter reg
100379 ** trigger program to use (REPLACE, IGNORE etc.). Parameter ignoreJump
100380 ** is the instruction that control should jump to if a trigger program
100385 Trigger *pTrigger, /* List of triggers on table pTab */
100394 Trigger *p; /* Used to iterate through pTrigger list */
100402 /* Sanity checking: The schema for the trigger and for the table are
100403 ** always defined. The trigger must be in the same schema as the table
100404 ** or else it must be a TEMP trigger. */
100410 /* Determine whether we should code this trigger */
100447 Trigger *pTrigger, /* List of triggers on table pTab */
100452 int orconf /* Default ON CONFLICT policy for trigger steps */
100456 Trigger *p;
100476 /************** End of trigger.c *********************************************/
100595 int isView; /* True when updating a view (INSTEAD OF trigger) */
100596 Trigger *pTrigger; /* List of triggers on pTab, if required */
100855 ** this record does not exist for some reason (deleted by a trigger,
100897 ** the database after the BEFORE triggers are fired anyway (as the trigger
100916 ** a new.* reference in a trigger program.
100935 /* The row-trigger may have deleted the row being updated. In this
100938 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
100943 /* If it did not delete it, the row-trigger may still have modified
101415 " WHERE type='view' OR type='trigger'"
107872 ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,
108661 26, /* TRIGGER => ID */
108761 "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
109085 /* 269 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
109114 /* 298 */ "cmd ::= DROP TRIGGER ifexists fullname",
110830 case 269: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
110939 case 298: /* cmd ::= DROP TRIGGER ifexists fullname */
111540 testcase( i==36 ); /* TRIGGER */
112153 ** Special handling is require for CREATE TRIGGER statements.
112154 ** Whenever the CREATE TRIGGER keywords are seen, the statement
112175 ** (5) TRIGGER We are in the middle of a trigger definition that must be
112179 ** the end of a trigger definition.
112182 ** of a trigger difinition.
112193 ** (6) tkTRIGGER The "trigger" keyword.
112200 ** to recognize the end of a trigger can be omitted. All we have to do
112208 /* A complex statement machine used to detect the end of a CREATE TRIGGER
112213 /* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
112219 /* 5 TRIGGER: */ { 6, 5, 5, 5, 5, 5, 5, 5, },
112310 if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
114573 ** do not block illegal combinations here, it could trigger