final class CreateTrigger
    implements Statement
    uses Snapshot
Public API: explicitly declared with @visibility public.

A request to create a trigger: a program of statements that runs when rows of a table change.

Rule: SQLITE-CREATE-TRIGGER-001. The facts are derived by SQLITE-TRIGGER-SCOPE-001. The statements of the program have the forms the trigger grammar admits: a query, or an INSERT, UPDATE or DELETE without a WITH clause and without a correlation name for the written table; an UPDATE or DELETE has no RETURNING clause. The statement executes nothing and provides no relation declaration. Source: https://sqlite.org/lang_createtrigger.html. Status: Implemented.

Reading the parts of a triggerdoctest
$trigger = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TEMP TRIGGER IF NOT EXISTS r AFTER UPDATE OF a ON t FOR EACH ROW WHEN new.a > old.a BEGIN DELETE FROM log; SELECT 1; END');
    $statement = $trigger->statement;
    [$statement->name->name->value, $statement->temporary, $statement->timing, $statement->columns[0]->value, $statement->forEachRow, count($statement->steps)] // => ['r', true, \SqlSemantics\Platform\Sqlite\Statement\Trigger\TriggerTiming::After, 'a', true, 2]
Refusing a program statement the trigger grammar does not admitdoctest
$delete = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('DELETE FROM t RETURNING a')->statement;
    new \SqlSemantics\Platform\Sqlite\Statement\Trigger\CreateTrigger(new \SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\QualifiedName(new \SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\Name('r')), \SqlSemantics\Platform\Sqlite\Statement\Trigger\TriggerEvent::Delete, new \SqlSemantics\Platform\Sqlite\Statement\Trigger\TriggerTable(new \SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\QualifiedName(new \SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\Name('t'))), [$delete]) // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvalidConstruction

Properties§

public list<Name> $columns
public TriggerEvent $event
public TriggerTable $table
public TriggerTiming|null $timing = null
public Scalar|null $when = null
public bool $forEachRow = false
public bool $temporary = false
public bool $ifNotExists = false

Methods§

public function __construct(
    public QualifiedName $name,
    public TriggerEvent $event,
    public TriggerTable $table,
    list<Select|ValuesClause|Compound|WithQuery|InsertRows|InsertSelect|Update|Delete> $steps,
    public TriggerTiming|null $timing = null,
    list<Name> $columns = [],
    public Scalar|null $when = null,
    public bool $forEachRow = false,
    public bool $temporary = false,
    public bool $ifNotExists = false,
)

Parameters

$nameQualifiedNameThe trigger name
$eventTriggerEventThe change that fires the trigger
$tableTriggerTableThe watched table
$stepslist<Select|ValuesClause|Compound|WithQuery|InsertRows|InsertSelect|Update|Delete>The statements of the program; at least one
$timingTriggerTiming|nullThe written timing
$columnslist<Name>The columns of UPDATE OF
$whenScalar|nullThe condition of WHEN
$forEachRowboolWhether FOR EACH ROW is written
$temporaryboolWhether TEMP or TEMPORARY is written
$ifNotExistsboolWhether IF NOT EXISTS is written

Throws

InvalidConstruction When a program statement is of no admitted form
Calls 14
public function deriveStatement(Derivation $derivation): void

Derives the watched table, the condition and the program.

Parameters

$derivationDerivation
Calls 2
public function render(Output $out): void

Writes the definition.

Parameters

$outOutput
Calls 8

Test cases 35§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 8
Other tests reaching this symbol 27

Relations§

Instantiated in 1
Type declarations 2