classUpdate
final class Update
implements Statement, Selection
uses Snapshot
@visibility public.An UPDATE of columns of the rows of a table that satisfy a predicate, optionally joined to further input.
Rule: SQLITE-UPDATE-001. The assigned values and the predicate see the written table and the relations of the FROM clause, which are derived by SQLITE-FROM-SCOPE-001; an assigned generated column is reported (SQLITE-GENERATED-WRITE-001); the rest follows SQLITE-MUTATION-SCOPE-001. Source: https://sqlite.org/lang_update.html. Status: Implemented.
$update = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('UPDATE OR FAIL t SET a = u.b FROM u WHERE t.id = u.id');
[$update->statement->resolution, count($update->statement->assignments), $update->statement->from->name->name->value] // => [\SqlSemantics\Platform\Sqlite\Statement\Mutation\ConflictResolution::Fail, 1, 'u']new \SqlSemantics\Platform\Sqlite\Statement\Mutation\Update(new \SqlSemantics\Platform\Sqlite\Statement\Mutation\MutationTarget(new \SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\QualifiedName(new \SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\Name('t'))), []) // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvalidConstructionProperties§
public non-empty-list<Assignment|RowAssignment> $assignmentspublic list<ResultColumn|Star|TableStar> $returningpublic MutationTarget $targetpublic Relation|null $from = nullpublic Scalar|null $where = nullpublic ConflictResolution|null $resolution = nullpublic WithClause|null $with = nullMethods§
public function __construct(
public MutationTarget $target,
list<Assignment|RowAssignment> $assignments,
public Relation|null $from = null,
public Scalar|null $where = null,
list<ResultColumn|Star|TableStar> $returning = [],
public ConflictResolution|null $resolution = null,
public WithClause|null $with = null,
)Parameters
$target | MutationTarget | The written table |
$assignments | list<Assignment|RowAssignment> | The assignments in written order; at least one |
$from | Relation|null | The further input relation |
$where | Scalar|null | The row predicate |
$returning | list<ResultColumn|Star|TableStar> | The RETURNING columns |
$resolution | ConflictResolution|null | The algorithm written after UPDATE OR |
$with | WithClause|null | The WITH clause of the statement |
Throws
InvalidConstruction When an assignment or a RETURNING column is of no admitted classCalls 7
- method-call ClosedList::of() line 76
- new ClosedList line 76
- class-const Assignment::class() line 76
- class-const RowAssignment::class() line 76
- class-const ResultColumn::class() line 77
- class-const Star::class() line 77
- class-const TableStar::class() line 77
public function input(): ?RelationAnswers the further input relation of the FROM clause.
Returns
public function deriveStatement(Derivation $derivation): voidDerives the statement as a root and records the rows of RETURNING as the output.
Parameters
$derivation | Derivation |
Calls 5
- method-call ProgramOnly::outsideProgram() line 93
- new ProgramOnly line 93
- method-call Update::deriveWithin() line 94
- method-call Derivation::environment() line 94
- method-call Derivation::output() line 96
public function deriveWithin(Derivation $derivation, Environment $outer): ?QueryFactDerives the statement inside an environment, as a trigger program does, and answers the rows it returns.
Parameters
$derivation | Derivation | |
$outer | Environment |
Returns
Called from 1
Calls 10
- new MutationScope line 105
- method-call MutationScope::open() line 106
- method-call FromScope::open() line 107
- new FromScope line 107
- new Environment line 108
- method-call MutationScope::assign() line 109
- method-call GeneratedWrites::assigned() line 110
- new GeneratedWrites line 110
- method-call Derivation::scalar() line 112
- method-call MutationScope::returning() line 115
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 2
- method-call Output::node() line 123
- method-call Output::keyword() line 125
Test cases 27§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 4
Other tests reaching this symbol 23
ConflictRuleTest::testOrConflictLowersTheAlgorithmAfterOrAndNullWithoutTheClausecallsMutationRuleTest::testAssignmentsKeepsTheWrittenOrderAndTheListFormcallsMutationRuleTest::testAssignmentsStartWithAListFormcallsMutationRuleTest::testCommandLowersEachDataChangeFormcallsMutationRuleTest::testUpdateLeavesEveryOptionalClauseEmptyWhenNotWrittencallsMutationRuleTest::testUpdateLowersEveryClauseInGrammarOrdercallsQueryCommandsTest::testCommandPassesDataChangesToTheMutationRulescallsWithRuleTest::testOptionalIsNullWithoutAWithClauseOnADataChangecallsTriggerRuleTest::testProgramLowersEveryStatementInWrittenOrdercallsTriggerRuleTest::testStepLowersAnUpdateWithEveryClausecallsTriggerRuleTest::testTargetLowersTheWrittenTableWithItsIndexChoiceAndReportsWhatSqliteRefusescallsGeneratedWritesTest::testWrittenAnswersTheGeneratedColumnANameDenotescallsMutationScopeTest::testOpenBindsTheWithClauseAndMakesTheTargetVisiblecallsTriggerFactsTest::testDeriveReportsTriggerOnlyMisusesAndTheColumnsOfUpdateOfcallsAssignmentTest::testRenderWritesTheColumnAnEqualsSignAndTheValuecallsAssignmentTest::testValueSeesTheRowOfTheTargetcallsConflictResolutionTest::testCasesAreReadAfterOrInInsertAndUpdatecallsMutationTargetTest::testAliasAnswersTheCorrelationNameOrNullcallsMutationTargetTest::testDeriveRelationResolvesAmongDeclaredTablesOnlycallsMutationTargetTest::testNameAnswersTheWrittenTableNamecallsRowAssignmentTest::testRenderWritesTheColumnListAndTheValuecallsCreateTriggerTest::testDeriveStatementResolvesNewAndOldToTheWatchedTablecallsCreateTriggerTest::testRejectsAStepWithAWithClausecalls
Relations§
Instantiated in 2
Constant reads 1
Type checks 3
- instanceof SqlSemantics\Platform\Sqlite\Rules\Mutation\TriggerFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/TriggerFacts.php:71
- instanceof SqlSemantics\Platform\Sqlite\Rules\Mutation\TriggerFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/TriggerFacts.php:72
- instanceof SqlSemantics\Platform\Sqlite\Statement\Trigger\CreateTrigger::__construct() packages/sql-semantics-sqlite/src/Statement/Trigger/CreateTrigger.php:91