Home | History | Annotate | Download | only in dist

Lines Matching refs:Trigger

288 ** A value of 1 means that a trigger program will not be able to itself
289 ** fire any triggers. A value of 0 means that no trigger programs at all
2029 ** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
2030 ** row is returned by this routine as long as the trigger is running.
2031 ** But once the trigger terminates, the value returned by this routine
2032 ** reverts to the last value inserted before the trigger fired.)^
2071 ** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
2080 ** A "trigger context" is a scope of execution that begins and
2081 ** ends with the script of a [CREATE TRIGGER | trigger].
2083 ** evaluated outside of any trigger. This is the "top level"
2084 ** trigger context. If a trigger fires from the top level, a
2085 ** new trigger context is entered for the duration of that one
2086 ** trigger. Subtriggers create subcontexts for their duration.
2089 ** not create a new trigger context.
2093 ** trigger context.
2097 ** that also occurred at the top level. ^(Within the body of a trigger,
2100 ** statement within the body of the same trigger.
2119 ** from all [CREATE TRIGGER | trigger] contexts and changes made by
2123 ** count does not include rows of views that fire an [INSTEAD OF trigger],
2124 ** though if the INSTEAD OF trigger makes changes of its own, those changes
2187 ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
2711 ** is the name of the inner-most trigger or view that is responsible for
2720 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
2722 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
2729 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
2731 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
2762 ** contain a UTF-8 SQL comment that identifies the trigger.)^
7398 typedef struct Trigger Trigger;
7749 ** A sub-routine used to implement a trigger program.
8910 ** trigger has its own context, so that lastRowid can be updated inside
8911 ** triggers as usual. The previous value will be restored once the trigger
8912 ** exits. Upon entering a before or instead of trigger, lastRowid is no
8921 ** within a trigger is not seen outside the trigger. Changes to views do not
8958 u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
9422 Trigger *pTrigger; /* List of triggers stored in pSchema */
9481 Trigger *apTrigger[2]; /* Triggers for aAction[] actions */
9910 ** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
10247 ** trigger that may be fired while parsing an INSERT, UPDATE or DELETE
10252 ** A Vdbe sub-program that implements the body and WHEN clause of trigger
10264 Trigger *pTrigger; /* Trigger this program was coded from */
10334 /* Information used while coding trigger programs. */
10340 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
10360 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
10404 * Each trigger present in the database schema is stored as an instance of
10405 * struct Trigger.
10407 * Pointers to instances of struct Trigger are stored in two ways.
10409 * database). This allows Trigger structures to be retrieved by name.
10411 * pNext member of struct Trigger. A pointer to the first element of the
10416 * containing the SQL statements specified as the trigger program.
10418 struct Trigger {
10419 char *zName; /* The name of the trigger */
10420 char *table; /* The table or view to which the trigger applies */
10424 IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
10426 Schema *pSchema; /* Schema containing the trigger */
10428 TriggerStep *step_list; /* Link list of trigger program steps */
10429 Trigger *pNext; /* Next trigger associated with the table */
10433 ** A trigger is either a BEFORE or an AFTER trigger. The following constants
10444 * that is a part of a trigger-program.
10448 * associated struct Trigger instance. The first element of the linked list is
10449 * the first step of the trigger-program.
10483 Trigger *pTrig; /* The trigger that this step is a part of */
10903 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int, Trigger *, int);
10937 SQLITE_PRIVATE void sqlite3DropTriggerPtr(Parse*, Trigger*);
10938 SQLITE_PRIVATE Trigger *sqlite3TriggersExist(Parse *, Table*, int, ExprList*, int *pMask);
10939 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *, Table *);
10940 SQLITE_PRIVATE void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, int, Table *,
10942 SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, int, int, int);
10950 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3*, Trigger*);
10952 SQLITE_PRIVATE u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int);
12015 ** a row trigger. The data for the row is stored in VdbeCursor.pData and
12568 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
17700 ** Trigger the alarm
56372 ** the trigger subprograms are listed one by one.
56406 ** the sum of the number of rows in all trigger subprograms encountered
56407 ** so far. The nRow value will increase as new trigger subprograms are
56414 ** to trigger subprograms. The VDBE is guaranteed to have at least 9
56809 ** is used, for example, when a trigger sub-program is halted to restore
60898 void *t; /* Token identifying trigger */
64451 ** This is used by trigger programs.
65207 ** the trigger named P4 in database P1. This is called after a trigger
65389 ** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
65398 ** P4 is a pointer to the VM containing the trigger program.
65409 void *t; /* Token identifying trigger */
65419 ** is really a trigger, not a foreign key action, and the flag set
65423 ** disabled. In some cases a single trigger may generate more than one
65424 ** SubProgram (if the trigger may be executed with more than one different
65426 ** single trigger all have the same value for the SubProgram.token
65436 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
65442 ** the trigger program. If this trigger has been fired before, then u.by.pRt
65508 ** address space. This is used by trigger programs to access the new.*
67829 ** it is a new.* or old.* trigger argument reference
68705 ** Y: The name of a table in a FROM clause. Or in a trigger
70398 ** * We are inside a trigger
71496 ** trigger programs. In this case Expr.iTable is set to 1 for the
71643 "RAISE() may only be used within a trigger-program");
72713 ** ALTER TABLE command. The first argument is the text of a CREATE TRIGGER
72715 ** TRIGGER statement is replaced with the third argument and the result
72717 ** TRIGGER, not CREATE INDEX and CREATE TABLE.
72737 /* The principle used to locate the table name in the CREATE TRIGGER
72770 ** "CREATE TRIGGER ... ON ON.ON BEGIN ..." etc.
72779 ** in the CREATE TRIGGER statement.
72861 Trigger *pTrig;
72866 ** returned, loop through the tables list of triggers. For each trigger
72879 char *zNew = sqlite3MPrintf(pParse->db, "type='trigger' AND (%s)", zWhere);
72899 Trigger *pTrig;
72920 /* Reload the table, index and permanent trigger schemas. */
73073 "WHEN type = 'trigger' THEN sqlite_rename_trigger(sql, %Q)"
73083 "(type='table' OR type='index' OR type='trigger');",
74474 const char *zType, /* "view", "trigger", or "index" */
74475 const Token *pName /* Name of the view, trigger, or index */
74495 ** These routines are used to make sure that an index, trigger, or
74588 TriggerStep *pStep /* The trigger step be fixed to one database */
74733 ** is in pTabList or else it is the NEW or OLD table of a trigger.
75472 /* The table or view or trigger name is passed to this routine via tokens
75521 ** trigger). All names are legal except those that begin with the string
76892 Trigger *pTrigger;
76932 ** dropped. Triggers are handled seperately because a trigger can be
76937 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
78968 sqlite3DeleteTrigger(0, (Trigger*)sqliteHashData(pElem));
79241 Trigger *pTrigger; /* List of table triggers, if required */
79480 Trigger *pTrigger, /* List of triggers to (potentially) fire */
79491 ** (this can happen if a trigger program has already deleted it), do
79520 /* Invoke BEFORE DELETE trigger programs. */
79553 /* Invoke AFTER DELETE trigger programs. */
79559 ** trigger programs were invoked. Or if a trigger program throws a
81823 ** The second argument is a Trigger structure allocated by the
81824 ** fkActionTrigger() routine. This function deletes the Trigger structure
81827 ** The Trigger structure or any of its sub-components may be allocated from
81830 static void fkTriggerDelete(sqlite3 *dbMem, Trigger *p){
82049 ** deferred trigger. That's what RESTRICT means. To defer checking
82156 ** It returns a pointer to a Trigger structure containing a trigger
82168 ** then the returned trigger structure is equivalent to:
82170 ** CREATE TRIGGER ... DELETE ON p BEGIN
82178 static Trigger *fkActionTrigger(
82186 Trigger *pTrigger; /* Trigger definition to return */
82198 TriggerStep *pStep = 0; /* First (only) step of trigger program */
82199 Expr *pWhere = 0; /* WHERE clause of trigger step */
82203 Expr *pWhen = 0; /* WHEN clause for the trigger */
82305 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
82306 sizeof(Trigger) + /* struct Trigger */
82307 sizeof(TriggerStep) + /* Single step in trigger program */
82372 ** trigger
82376 Trigger *pAction = fkActionTrigger(pParse, pTab, pFKey, pChanges);
82659 /* This routine is never called during trigger-generation. It is
82902 Trigger *pTrigger; /* List of triggers on pTab, if required */
82903 int tmask; /* Mask of trigger times */
83242 ** translated into a unique ID for the row. But on a BEFORE trigger,
83287 /* If this is an INSERT on a view with an INSTEAD OF INSERT trigger,
83709 Trigger *pTrigger = 0;
83820 Trigger *pTrigger = 0;
85673 /* This flag may only be set if both foreign-key and trigger support
87033 ** argv[1] = root page number for table or index. 0 for trigger or view.
88559 ** the body of a TRIGGER. The purpose of such selects is to call
88857 /* At one time, code such as "SELECT new.x" within a trigger would
88859 ** trigger code is generated and so this condition is no longer
92475 /************** Begin file trigger.c *****************************************/
92509 ** the table. The list is connected by Trigger.pNext pointers.
92521 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
92523 Trigger *pList = 0; /* List of triggers to return */
92532 Trigger *pTrig = (Trigger *)sqliteHashData(p);
92546 ** This is called by the parser when it sees a CREATE TRIGGER statement
92547 ** up to the point of the BEGIN before the trigger actions. A Trigger
92549 ** in pParse->pNewTrigger. After the trigger actions have been parsed, the
92550 ** sqlite3FinishTrigger() function is called to complete the trigger
92554 Parse *pParse, /* The parse context of the CREATE TRIGGER statement */
92555 Token *pName1, /* The name of the trigger */
92556 Token *pName2, /* The name of the trigger */
92559 IdList *pColumns, /* column list if this is an UPDATE OF trigger */
92560 SrcList *pTableName,/* The name of the table/view the trigger applies to */
92563 int noErr /* Suppress errors if the trigger already exists */
92565 Trigger *pTrigger = 0; /* The new trigger */
92566 Table *pTab; /* Table that the trigger fires off of */
92567 char *zName = 0; /* Name of the trigger */
92569 int iDb; /* The database to store the trigger in */
92579 /* If TEMP was specified, then the trigger name may not be qualified. */
92581 sqlite3ErrorMsg(pParse, "temporary trigger may not have qualified name");
92587 /* Figure out the db that the the trigger will be created in */
92594 /* If the trigger name was unqualified, and the table is a temp table,
92595 ** then set iDb to 1 to create the trigger in the temporary database.
92611 if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) &&
92621 ** dropped too. But if a TEMP trigger is created on a non-TEMP table
92623 ** trigger is not visible to the database connection that does the
92624 ** drop so the trigger cannot be dropped. This results in an
92625 ** "orphaned trigger" - a trigger whose associated table is missing.
92636 /* Check that the trigger name is not reserved and that no trigger of the
92645 sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
92650 /* Do not create a trigger on a system table */
92652 sqlite3ErrorMsg(pParse, "cannot create trigger on system table");
92661 sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S",
92667 " trigger on table: %S", pTableName, 0);
92689 ** INSTEAD OF trigger into a BEFORE trigger. It simplifies code
92696 /* Build the Trigger object */
92697 pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
92724 ** This routine is called after all of the trigger actions have been parsed
92725 ** in order to complete the process of building the trigger.
92730 Token *pAll /* Token that describes the complete CREATE TRIGGER */
92732 Trigger *pTrig = pParse->pNewTrigger; /* Trigger being finished */
92733 char *zName; /* Name of trigger */
92736 int iDb; /* Database containing the trigger */
92737 Token nameToken; /* Trigger name for error reporting */
92751 if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken)
92769 "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
92775 db, "type='trigger' AND name='%q'", zName), P4_DYNAMIC
92780 Trigger *pLink = pTrig;
92803 ** a trigger step. Return a pointer to a TriggerStep structure.
92806 ** body of a TRIGGER.
92821 ** Allocate space to hold a new trigger step. The allocated space
92828 u8 op, /* Trigger opcode */
92845 ** Build a trigger step out of an INSERT statement. Return a pointer
92846 ** to the new trigger step.
92849 ** body of a trigger.
92880 ** Construct a trigger step that implements an UPDATE statement and return
92881 ** a pointer to that trigger step. The parser calls this routine when it
92882 ** sees an UPDATE statement inside the body of a CREATE TRIGGER.
92905 ** Construct a trigger step that implements a DELETE statement and return
92906 ** a pointer to that trigger step. The parser calls this routine when it
92907 ** sees a DELETE statement inside the body of a CREATE TRIGGER.
92926 ** Recursively delete a Trigger structure
92928 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *db, Trigger *pTrigger){
92939 ** This function is called to drop a trigger from the database schema.
92942 ** the trigger by name. The sqlite3DropTriggerPtr() routine does the
92943 ** same job as this routine except it takes a pointer to the trigger
92944 ** instead of the trigger name.
92947 Trigger *pTrigger = 0;
92971 sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);
92983 ** Return a pointer to the Table structure for the table that a trigger
92986 static Table *tableOfTrigger(Trigger *pTrigger){
92993 ** Drop a trigger given a pointer to that trigger.
92995 SQLITE_PRIVATE void sqlite3DropTriggerPtr(Parse *pParse, Trigger *pTrigger){
93019 /* Generate code to destroy the database record of the trigger.
93029 { OP_String8, 0, 1, 0}, /* 4: "trigger" */
93040 sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
93051 ** Remove a trigger from the hash tables of the sqlite* pointer.
93055 Trigger *pTrigger;
93060 Trigger **pp;
93089 ** one trigger that must be fired when an operation of type 'op' is
93093 SQLITE_PRIVATE Trigger *sqlite3TriggersExist(
93101 Trigger *pList = sqlite3TriggerList(pParse, pTab);
93102 Trigger *p;
93120 ** forming the SrcList. This prevents a trigger in one database from
93122 ** trigger is in TEMP in which case it can refer to any other database it
93127 TriggerStep *pStep /* The trigger containing the target token */
93148 ** trigger.
93152 TriggerStep *pStepList, /* List of statements inside the trigger body */
93164 ** of the trigger program. If the statement that caused this trigger
93166 ** the ON CONFLICT policy that was specified as part of the trigger
93169 ** CREATE TRIGGER AFTER INSERT ON t1 BEGIN;
93242 ** (trigger program). If an error has occurred, transfer error information
93258 ** implementing trigger pTrigger with ON CONFLICT policy orconf.
93262 Trigger *pTrigger, /* Trigger to code */
93264 int orconf /* ON CONFLICT policy to code trigger program with */
93269 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
93272 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
93295 ** trigger sub-program. */
93319 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
93337 /* Code the trigger program into the sub-vdbe. */
93368 ** trigger pTrigger with default ON CONFLICT algorithm orconf. If no such
93374 Trigger *pTrigger, /* Trigger to code */
93375 Table *pTab, /* The table trigger pTrigger is attached to */
93383 /* It may be that this trigger has already been coded (or is in the
93401 ** Generate code for the trigger program associated with trigger p on
93408 Trigger *p, /* Trigger to code */
93420 ** is a pointer to the sub-vdbe containing the trigger program. */
93430 ** recursive invocation of this trigger program is disallowed. Recursive
93431 ** invocation is disallowed if (a) the sub-program is really a trigger,
93450 ** in the trigger program. If N is the number of columns in table pTab
93465 ** never be accessed by the trigger program, so they are not allocated or
93469 ** ON INSERT trigger, the value passed to this function as parameter reg
93474 ** trigger program to use (REPLACE, IGNORE etc.). Parameter ignoreJump
93475 ** is the instruction that control should jump to if a trigger program
93480 Trigger *pTrigger, /* List of triggers on table pTab */
93489 Trigger *p; /* Used to iterate through pTrigger list */
93497 /* Sanity checking: The schema for the trigger and for the table are
93498 ** always defined. The trigger must be in the same schema as the table
93499 ** or else it must be a TEMP trigger. */
93505 /* Determine whether we should code this trigger */
93542 Trigger *pTrigger, /* List of triggers on table pTab */
93547 int orconf /* Default ON CONFLICT policy for trigger steps */
93551 Trigger *p;
93571 /************** End of trigger.c *********************************************/
93689 int isView; /* True when updating a view (INSTEAD OF trigger) */
93690 Trigger *pTrigger; /* List of triggers on pTab, if required */
93948 ** this record does not exist for some reason (deleted by a trigger,
93990 ** the database after the BEFORE triggers are fired anyway (as the trigger
94008 ** a new.* reference in a trigger program.
94027 /* The row-trigger may have deleted the row being updated. In this
94030 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
94035 /* If it did not delete it, the row-trigger may still have modified
94500 " WHERE type='view' OR type='trigger'"
100256 ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,
101033 26, /* TRIGGER => ID */
101132 "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
101458 /* 271 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
101487 /* 300 */ "cmd ::= DROP TRIGGER ifexists fullname",
103172 case 271: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
103281 case 300: /* cmd ::= DROP TRIGGER ifexists fullname */
103881 testcase( i==36 ); /* TRIGGER */
104495 ** Special handling is require for CREATE TRIGGER statements.
104496 ** Whenever the CREATE TRIGGER keywords are seen, the statement
104517 ** (5) TRIGGER We are in the middle of a trigger definition that must be
104521 ** the end of a trigger definition.
104524 ** of a trigger difinition.
104535 ** (6) tkTRIGGER The "trigger" keyword.
104542 ** to recognize the end of a trigger can be omitted. All we have to do
104550 /* A complex statement machine used to detect the end of a CREATE TRIGGER
104555 /* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
104561 /* 5 TRIGGER: */ { 6, 5, 5, 5, 5, 5, 5, 5, },
104652 if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
106560 ** do not block illegal combinations here, it could trigger