Lines Matching full:trigger
275 ** A value of 1 means that a trigger program will not be able to itself
276 ** fire any triggers. A value of 0 means that no trigger programs at all
1847 ** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
1848 ** row is returned by this routine as long as the trigger is running.
1849 ** But once the trigger terminates, the value returned by this routine
1850 ** reverts to the last value inserted before the trigger fired.)^
1889 ** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
1898 ** A "trigger context" is a scope of execution that begins and
1899 ** ends with the script of a [CREATE TRIGGER | trigger].
1901 ** evaluated outside of any trigger. This is the "top level"
1902 ** trigger context. If a trigger fires from the top level, a
1903 ** new trigger context is entered for the duration of that one
1904 ** trigger. Subtriggers create subcontexts for their duration.
1907 ** not create a new trigger context.
1911 ** trigger context.
1915 ** that also occurred at the top level. ^(Within the body of a trigger,
1918 ** statement within the body of the same trigger.
1937 ** from all [CREATE TRIGGER | trigger] contexts and changes made by
1941 ** count does not include rows of views that fire an [INSTEAD OF trigger],
1942 ** though if the INSTEAD OF trigger makes changes of its own, those changes
2005 ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
2524 ** is the name of the inner-most trigger or view that is responsible for
2533 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
2535 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
2542 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
2544 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
2576 ** contain a UTF-8 SQL comment that identifies the trigger.)^
6808 typedef struct Trigger Trigger;
7144 ** A sub-routine used to implement a trigger program.
8288 ** trigger has its own context, so that lastRowid can be updated inside
8289 ** triggers as usual. The previous value will be restored once the trigger
8290 ** exits. Upon entering a before or instead of trigger, lastRowid is no
8299 ** within a trigger is not seen outside the trigger. Changes to views do not
8337 u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
8770 Trigger *pTrigger; /* List of triggers stored in pSchema */
8829 Trigger *apTrigger[2]; /* Triggers for aAction[] actions */
9258 ** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
9585 ** trigger that may be fired while parsing an INSERT, UPDATE or DELETE
9590 ** A Vdbe sub-program that implements the body and WHEN clause of trigger
9602 Trigger *pTrigger; /* Trigger this program was coded from */
9672 /* Information used while coding trigger programs. */
9678 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
9697 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
9736 * Each trigger present in the database schema is stored as an instance of
9737 * struct Trigger.
9739 * Pointers to instances of struct Trigger are stored in two ways.
9741 * database). This allows Trigger structures to be retrieved by name.
9743 * pNext member of struct Trigger. A pointer to the first element of the
9748 * containing the SQL statements specified as the trigger program.
9750 struct Trigger {
9751 char *zName; /* The name of the trigger */
9752 char *table; /* The table or view to which the trigger applies */
9756 IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
9758 Schema *pSchema; /* Schema containing the trigger */
9760 TriggerStep *step_list; /* Link list of trigger program steps */
9761 Trigger *pNext; /* Next trigger associated with the table */
9765 ** A trigger is either a BEFORE or an AFTER trigger. The following constants
9776 * that is a part of a trigger-program.
9780 * associated struct Trigger instance. The first element of the linked list is
9781 * the first step of the trigger-program.
9815 Trigger *pTrig; /* The trigger that this step is a part of */
10221 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int, Trigger *, int);
10255 SQLITE_PRIVATE void sqlite3DropTriggerPtr(Parse*, Trigger*);
10256 SQLITE_PRIVATE Trigger *sqlite3TriggersExist(Parse *, Table*, int, ExprList*, int *pMask);
10257 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *, Table *);
10258 SQLITE_PRIVATE void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, int, Table *,
10260 SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, int, int, int);
10268 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3*, Trigger*);
10270 SQLITE_PRIVATE u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int);
15822 ** Trigger the alarm
17561 ** a row trigger. The data for the row is stored in VdbeCursor.pData and
48465 ** the trigger subprograms are listed one by one.
48499 ** the sum of the number of rows in all trigger subprograms encountered
48500 ** so far. The nRow value will increase as new trigger subprograms are
48507 ** to trigger subprograms. The VDBE is guaranteed to have at least 9
48903 ** is used, for example, when a trigger sub-program is halted to restore
52893 void *t; /* Token identifying trigger */
56397 ** This is used by trigger programs.
57139 ** the trigger named P4 in database P1. This is called after a trigger
57321 ** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
57330 ** P4 is a pointer to the VM containing the trigger program.
57341 void *t; /* Token identifying trigger */
57350 ** is really a trigger, not a foreign key action, and the flag set
57354 ** disabled. In some cases a single trigger may generate more than one
57355 ** SubProgram (if the trigger may be executed with more than one different
57357 ** single trigger all have the same value for the SubProgram.token
57367 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
57373 ** the trigger program. If this trigger has been fired before, then u.by.pRt
57439 ** address space. This is used by trigger programs to access the new.*
59527 ** it is a new.* or old.* trigger argument reference
60400 ** Y: The name of a table in a FROM clause. Or in a trigger
62080 ** * We are inside a trigger
63210 ** trigger programs. In this case Expr.iTable is set to 1 for the
63350 "RAISE() may only be used within a trigger-program");
64391 ** ALTER TABLE command. The first argument is the text of a CREATE TRIGGER
64393 ** TRIGGER statement is replaced with the third argument and the result
64395 ** TRIGGER, not CREATE INDEX and CREATE TABLE.
64415 /* The principle used to locate the table name in the CREATE TRIGGER
64448 ** "CREATE TRIGGER ... ON ON.ON BEGIN ..." etc.
64457 ** in the CREATE TRIGGER statement.
64533 Trigger *pTrig;
64538 ** returned, loop through the tables list of triggers. For each trigger
64566 Trigger *pTrig;
64587 /* Reload the table, index and permanent trigger schemas. */
64737 "WHEN type = 'trigger' THEN sqlite_rename_trigger(sql, %Q)"
64747 "(type='table' OR type='index' OR type='trigger');",
66089 const char *zType, /* "view", "trigger", or "index" */
66090 const Token *pName /* Name of the view, trigger, or index */
66110 ** These routines are used to make sure that an index, trigger, or
66203 TriggerStep *pStep /* The trigger step be fixed to one database */
66348 ** is in pTabList or else it is the NEW or OLD table of a trigger.
67107 /* The table or view or trigger name is passed to this routine via tokens
67156 ** trigger). All names are legal except those that begin with the string
68525 Trigger *pTrigger;
68565 ** dropped. Triggers are handled seperately because a trigger can be
68570 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
70591 sqlite3DeleteTrigger(0, (Trigger*)sqliteHashData(pElem));
70865 Trigger *pTrigger; /* List of table triggers, if required */
71104 Trigger *pTrigger, /* List of triggers to (potentially) fire */
71115 ** (this can happen if a trigger program has already deleted it), do
71146 /* Invoke BEFORE DELETE trigger programs. */
71179 /* Invoke AFTER DELETE trigger programs. */
71185 ** trigger programs were invoked. Or if a trigger program throws a
73378 ** The second argument is a Trigger structure allocated by the
73379 ** fkActionTrigger() routine. This function deletes the Trigger structure
73382 ** The Trigger structure or any of its sub-components may be allocated from
73385 static void fkTriggerDelete(sqlite3 *dbMem, Trigger *p){
73604 ** deferred trigger. That's what RESTRICT means. To defer checking
73711 ** It returns a pointer to a Trigger structure containing a trigger
73723 ** then the returned trigger structure is equivalent to:
73725 ** CREATE TRIGGER ... DELETE ON p BEGIN
73733 static Trigger *fkActionTrigger(
73741 Trigger *pTrigger; /* Trigger definition to return */
73753 TriggerStep *pStep = 0; /* First (only) step of trigger program */
73754 Expr *pWhere = 0; /* WHERE clause of trigger step */
73758 Expr *pWhen = 0; /* WHEN clause for the trigger */
73864 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
73865 sizeof(Trigger) + /* struct Trigger */
73866 sizeof(TriggerStep) + /* Single step in trigger program */
73931 ** trigger sub-program. */
73935 Trigger *pAction = fkActionTrigger(pParse, pTab, pFKey, pChanges);
74216 /* This routine is never called during trigger-generation. It is
74459 Trigger *pTrigger; /* List of triggers on pTab, if required */
74460 int tmask; /* Mask of trigger times */
74799 ** translated into a unique ID for the row. But on a BEFORE trigger,
74844 /* If this is an INSERT on a view with an INSTEAD OF INSERT trigger,
75252 Trigger *pTrigger = 0;
75362 Trigger *pTrigger = 0;
77132 /* This flag may only be set if both foreign-key and trigger support
78419 ** argv[1] = root page number for table or index. 0 for trigger or view.
79943 ** the body of a TRIGGER. The purpose of such selects is to call
80163 /* At one time, code such as "SELECT new.x" within a trigger would
80165 ** trigger code is generated and so this condition is no longer
83714 /************** Begin file trigger.c *****************************************/
83748 ** the table. The list is connected by Trigger.pNext pointers.
83760 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
83762 Trigger *pList = 0; /* List of triggers to return */
83771 Trigger *pTrig = (Trigger *)sqliteHashData(p);
83785 ** This is called by the parser when it sees a CREATE TRIGGER statement
83786 ** up to the point of the BEGIN before the trigger actions. A Trigger
83788 ** in pParse->pNewTrigger. After the trigger actions have been parsed, the
83789 ** sqlite3FinishTrigger() function is called to complete the trigger
83793 Parse *pParse, /* The parse context of the CREATE TRIGGER statement */
83794 Token *pName1, /* The name of the trigger */
83795 Token *pName2, /* The name of the trigger */
83798 IdList *pColumns, /* column list if this is an UPDATE OF trigger */
83799 SrcList *pTableName,/* The name of the table/view the trigger applies to */
83802 int noErr /* Suppress errors if the trigger already exists */
83804 Trigger *pTrigger = 0; /* The new trigger */
83805 Table *pTab; /* Table that the trigger fires off of */
83806 char *zName = 0; /* Name of the trigger */
83808 int iDb; /* The database to store the trigger in */
83818 /* If TEMP was specified, then the trigger name may not be qualified. */
83820 sqlite3ErrorMsg(pParse, "temporary trigger may not have qualified name");
83826 /* Figure out the db that the the trigger will be created in */
83833 /* If the trigger name was unqualified, and the table is a temp table,
83834 ** then set iDb to 1 to create the trigger in the temporary database.
83849 if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) &&
83859 ** dropped too. But if a TEMP trigger is created on a non-TEMP table
83861 ** trigger is not visible to the database connection that does the
83862 ** drop so the trigger cannot be dropped. This results in an
83863 ** "orphaned trigger" - a trigger whose associated table is missing.
83874 /* Check that the trigger name is not reserved and that no trigger of the
83883 sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
83888 /* Do not create a trigger on a system table */
83890 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
83899 sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
83905 " trigger on table: %S", pTableName, 0);
83927 ** INSTEAD OF trigger into a BEFORE trigger. It simplifies code
83934 /* Build the Trigger object */
83935 pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
83962 ** This routine is called after all of the trigger actions have been parsed
83963 ** in order to complete the process of building the trigger.
83968 Token *pAll /* Token that describes the complete CREATE TRIGGER */
83970 Trigger *pTrig = pParse->pNewTrigger; /* Trigger being finished */
83971 char *zName; /* Name of trigger */
83974 int iDb; /* Database containing the trigger */
83975 Token nameToken; /* Trigger name for error reporting */
83989 if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken)
83994 /* if we are not initializing, and this trigger is not on a TEMP table,
84007 "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
84013 db, "type='trigger' AND name='%q'", zName), P4_DYNAMIC
84018 Trigger *pLink = pTrig;
84041 ** a trigger step. Return a pointer to a TriggerStep structure.
84044 ** body of a TRIGGER.
84059 ** Allocate space to hold a new trigger step. The allocated space
84066 u8 op, /* Trigger opcode */
84083 ** Build a trigger step out of an INSERT statement. Return a pointer
84084 ** to the new trigger step.
84087 ** body of a trigger.
84118 ** Construct a trigger step that implements an UPDATE statement and return
84119 ** a pointer to that trigger step. The parser calls this routine when it
84120 ** sees an UPDATE statement inside the body of a CREATE TRIGGER.
84143 ** Construct a trigger step that implements a DELETE statement and return
84144 ** a pointer to that trigger step. The parser calls this routine when it
84145 ** sees a DELETE statement inside the body of a CREATE TRIGGER.
84164 ** Recursively delete a Trigger structure
84166 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *db, Trigger *pTrigger){
84177 ** This function is called to drop a trigger from the database schema.
84180 ** the trigger by name. The sqlite3DropTriggerPtr() routine does the
84181 ** same job as this routine except it takes a pointer to the trigger
84182 ** instead of the trigger name.
84185 Trigger *pTrigger = 0;
84209 sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);
84220 ** Return a pointer to the Table structure for the table that a trigger
84223 static Table *tableOfTrigger(Trigger *pTrigger){
84230 ** Drop a trigger given a pointer to that trigger.
84232 SQLITE_PRIVATE void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger){
84256 /* Generate code to destroy the database record of the trigger.
84266 { OP_String8, 0, 1, 0}, /* 4: "trigger" */
84277 sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
84288 ** Remove a trigger from the hash tables of the sqlite* pointer.
84292 Trigger *pTrigger;
84297 Trigger **pp;
84326 ** one trigger that must be fired when an operation of type 'op' is
84330 SQLITE_PRIVATE Trigger *sqlite3TriggersExist(
84338 Trigger *pList = sqlite3TriggerList(pParse, pTab);
84339 Trigger *p;
84357 ** forming the SrcList. This prevents a trigger in one database from
84359 ** trigger is in TEMP in which case it can refer to any other database it
84364 TriggerStep *pStep /* The trigger containing the target token */
84385 ** trigger.
84389 TriggerStep *pStepList, /* List of statements inside the trigger body */
84401 ** of the trigger program. If the statement that caused this trigger
84403 ** the ON CONFLICT policy that was specified as part of the trigger
84406 ** CREATE TRIGGER AFTER INSERT ON t1 BEGIN;
84479 ** (trigger program). If an error has occurred, transfer error information
84495 ** implementing trigger pTrigger with ON CONFLICT policy orconf.
84499 Trigger *pTrigger, /* Trigger to code */
84501 int orconf /* ON CONFLICT policy to code trigger program with */
84506 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
84509 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
84531 ** trigger sub-program. */
84554 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
84572 /* Code the trigger program into the sub-vdbe. */
84603 ** trigger pTrigger with default ON CONFLICT algorithm orconf. If no such
84609 Trigger *pTrigger, /* Trigger to code */
84610 Table *pTab, /* The table trigger pTrigger is attached to */
84618 /* It may be that this trigger has already been coded (or is in the
84636 ** Generate code for the trigger program associated with trigger p on
84643 Trigger *p, /* Trigger to code */
84655 ** is a pointer to the sub-vdbe containing the trigger program. */
84664 ** recursive invocation of this trigger program is disallowed. Recursive
84665 ** invocation is disallowed if (a) the sub-program is really a trigger,
84684 ** in the trigger program. If N is the number of columns in table pTab
84699 ** never be accessed by the trigger program, so they are not allocated or
84703 ** ON INSERT trigger, the value passed to this function as parameter reg
84708 ** trigger program to use (REPLACE, IGNORE etc.). Parameter ignoreJump
84709 ** is the instruction that control should jump to if a trigger program
84714 Trigger *pTrigger, /* List of triggers on table pTab */
84723 Trigger *p; /* Used to iterate through pTrigger list */
84731 /* Sanity checking: The schema for the trigger and for the table are
84732 ** always defined. The trigger must be in the same schema as the table
84733 ** or else it must be a TEMP trigger. */
84739 /* Determine whether we should code this trigger */
84776 Trigger *pTrigger, /* List of triggers on table pTab */
84781 int orconf /* Default ON CONFLICT policy for trigger steps */
84785 Trigger *p;
84805 /************** End of trigger.c *********************************************/
84923 int isView; /* True when updating a view (INSTEAD OF trigger) */
84924 Trigger *pTrigger; /* List of triggers on pTab, if required */
85181 ** this record does not exist for some reason (deleted by a trigger,
85224 ** the database after the BEFORE triggers are fired anyway (as the trigger
85242 ** a new.* reference in a trigger program.
85261 /* The row-trigger may have deleted the row being updated. In this
85264 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
85269 /* If it did not delete it, the row-trigger may still have modified
85719 " WHERE type='view' OR type='trigger'"
90901 ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,
91677 26, /* TRIGGER => ID */
91776 "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
92104 /* 272 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
92133 /* 301 */ "cmd ::= DROP TRIGGER ifexists fullname",
93801 case 272: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
93910 case 301: /* cmd ::= DROP TRIGGER ifexists fullname */
94510 testcase( i==36 ); /* TRIGGER */
95124 ** Special handling is require for CREATE TRIGGER statements.
95125 ** Whenever the CREATE TRIGGER keywords are seen, the statement
95146 ** (5) TRIGGER We are in the middle of a trigger definition that must be
95150 ** the end of a trigger definition.
95153 ** of a trigger difinition.
95164 ** (6) tkTRIGGER The "trigger" keyword.
95171 ** to recognize the end of a trigger can be omitted. All we have to do
95179 /* A complex statement machine used to detect the end of a CREATE TRIGGER
95184 /* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
95190 /* 5 TRIGGER: */ { 6, 5, 5, 5, 5, 5, 5, 5, },
95281 if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){