classCreateTrigger
final class CreateTrigger
implements Statement
uses Snapshot
Public API: explicitly declared with
@visibility public.CREATE TRIGGER: a statement that runs for each row an INSERT, UPDATE or DELETE changes in a table.
The statement is structured as a request: it declares nothing to a context. The facts follow MYSQL-TRIGGER-001. Source: https://dev.mysql.com/doc/refman/8.4/en/create-trigger.html.
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE TRIGGER tr BEFORE UPDATE ON t FOR EACH ROW SET @changed = 1');
[$create->statement->time->value, $create->statement->event->value, $create->statement->table->name->name->value] // => ['BEFORE', 'UPDATE', 't']Properties§
public ProgramStatement|Statement $bodypublic QualifiedName $namepublic TriggerTime $timepublic TriggerEvent $eventpublic TriggerTable $tablepublic TriggerOrder|null $order = nullpublic Account|null $definer = nullpublic bool $ifNotExists = falseMethods§
public function __construct(
public QualifiedName $name,
public TriggerTime $time,
public TriggerEvent $event,
public TriggerTable $table,
Node $body,
public TriggerOrder|null $order = null,
public Account|null $definer = null,
public bool $ifNotExists = false,
)Parameters
$name | QualifiedName | The trigger name with its optional database |
$time | TriggerTime | Whether the trigger runs before or after the row change |
$event | TriggerEvent | The kind of row change that activates the trigger |
$table | TriggerTable | The table the trigger belongs to |
$body | Node | The statement the trigger runs: a program statement or an SQL statement |
$order | TriggerOrder|null | The FOLLOWS or PRECEDES clause (MySQL 5.7 and later) |
$definer | Account|null | The DEFINER clause, when written |
$ifNotExists | bool | Whether IF NOT EXISTS is written (MySQL 8.0.29 and later) |
Throws
InvalidConstruction When the body is of another classCalls 3
- static-call Check::input() line 67
- method-call StatementSequence::member() line 68
- new StatementSequence line 68
public function deriveStatement(Derivation $derivation): voidDerives the table and the body, in which NEW and OLD denote the row of the table.
Parameters
$derivation | Derivation |
Calls 2
- method-call ProgramFacts::trigger() line 76
- new ProgramFacts line 76
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 84
- method-call ProgramNames::qualified() line 92
- new ProgramNames line 92
Test cases 15§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 3
Other tests reaching this symbol 12
DefinitionTailsTest::testCreateHandsADefinerTailToTheFamilyOfTheObjectcallsStatementRuleTest::testStatementsLowersTheListInOrdercallsRoutineRulesTest::testCreateLowersEveryKindOfStoredProgramcallsTriggerRuleTest::testCreateLowersATriggerOfEveryLayoutcallsTriggerRuleTest::testCreateReadsIfNotExistscallsTriggerRuleTest::testOrderLowersFollowsAndPrecedescallsRowAliasesTest::testVisibleResolvesTheOldRowToTheTriggerTablecallsTriggerOrderTest::testRenderWritesThePlacementAndTheOtherTriggercallsTriggerTableTest::testDeriveRelationAnswersTheRowOfTheDeclaredTablecallsTriggerTableTest::testDeriveRelationDoesNotFindATableOfAnotherDatabasecallsTriggerTableTest::testDeriveRelationLeavesTheShapeOpenForAnUndeclaredTablecallsTriggerTableTest::testDeriveRelationReportsATableTheCompleteContextLackscalls