classMutationScope
final class MutationScope
Derives the parts that INSERT, UPDATE and DELETE share.
Rule: SQLITE-MUTATION-SCOPE-001. The common tables of the statement are bound first and are visible in every query of the statement. The written table is one visible relation under its correlation name, or its table name when it has none. A column named by a column list or an assignment must be a column of the written table, or its rowid; a name the table certainly lacks is reported. A row assignment needs a row of as many values as columns. RETURNING sees the written table only; its result columns follow SQLITE-RESULT-NAME-001 and are the output of the statement. Source: https://sqlite.org/lang_update.html, https://sqlite.org/lang_returning.html, https://sqlite.org/lang_with.html. Status: Implemented.
Methods§
public function open(
MutationTarget $target,
?WithClause $with,
Derivation $derivation,
Environment $outer,
): array{Environment, VisibleRelation, RelationFact}Binds the common tables and derives the written table.
Parameters
$target | MutationTarget | |
$with | ?WithClause | |
$derivation | Derivation | |
$outer | Environment |
Returns
array{Environment, VisibleRelation, RelationFact} The environment the queries of the statement are nested in, the written table as a visible relation, and its factsTest cases 7
GeneratedWritesTest::testRowidTargetRecognisesASingleNameOfTheRowidcallsGeneratedWritesTest::testSuppliedTellsWhetherTheInsertedRowSuppliesTheRowidcallsGeneratedWritesTest::testWrittenAnswersTheGeneratedColumnANameDenotescallsMutationScopeTest::testAssignChecksTheColumnsAndTheWidthOfEachAssignmentcallsMutationScopeTest::testNamesReportsColumnsAClosedTargetCertainlyLackscallsMutationScopeTest::testOpenBindsTheWithClauseAndMakesTheTargetVisiblecallsMutationScopeTest::testReturningIsNullWithoutColumnsAndProjectsTheTargetOtherwisecalls
Called from 3
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:55
- method-call SqlSemantics\Platform\Sqlite\Statement\Mutation\Delete::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Delete.php:74
- method-call SqlSemantics\Platform\Sqlite\Statement\Mutation\Update::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Update.php:106
Calls 6
- method-call CommonTables::bind() line 55
- new CommonTables line 55
- method-call Derivation::relation() line 56
- new VisibleRelation line 58
- method-call TableShapes::implicit() line 58
- new TableShapes line 58
public function names(
list<Name> $columns,
VisibleRelation $target,
Derivation $derivation,
): voidReports the names that are certainly no column of the written table.
Parameters
$columns | list<Name> | |
$target | VisibleRelation | |
$derivation | Derivation |
Test cases 1
Called from 3
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:59
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\MutationScope::assign() packages/sql-semantics-sqlite/src/Rules/Mutation/MutationScope.php:92
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\TriggerFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/TriggerFacts.php:65
Calls 5
- new Joining line 68
- method-call Joining::locate() line 70
- method-call Joining::closed() line 76
- method-call Derivation::report() line 77
- new MissingColumn line 77
public function assign(
list<Assignment|RowAssignment> $assignments,
VisibleRelation $target,
Derivation $derivation,
Environment $environment,
): voidDerives the assignments of an UPDATE or of an upsert.
Parameters
$assignments | list<Assignment|RowAssignment> | |
$target | VisibleRelation | |
$derivation | Derivation | |
$environment | Environment |
Test cases 1
Called from 2
Calls 6
- method-call Derivation::scalar() line 90
- method-call MutationScope::names() line 92
- function-call
countline 95 - method-call Derivation::report() line 96
- new ArityMismatch line 96
- class-const ArityRule::RowAssignment() line 96
public function returning(
list<ResultColumn|Star|TableStar> $columns,
VisibleRelation $target,
Derivation $derivation,
Environment $base,
): ?QueryFactDerives a RETURNING clause and answers the rows it returns, or null when there is none.
Parameters
$columns | list<ResultColumn|Star|TableStar> | |
$target | VisibleRelation | |
$derivation | Derivation | |
$base | Environment |
Returns
Called from 3
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:90
- method-call SqlSemantics\Platform\Sqlite\Statement\Mutation\Delete::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Delete.php:79
- method-call SqlSemantics\Platform\Sqlite\Statement\Mutation\Update::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Update.php:115
Calls 4
- new QueryFact line 113
- method-call Projection::items() line 113
- new Projection line 113
- new Environment line 113
Test cases 7§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 4
MutationScopeTest::testAssignChecksTheColumnsAndTheWidthOfEachAssignmentcallsMutationScopeTest::testNamesReportsColumnsAClosedTargetCertainlyLackscallsMutationScopeTest::testOpenBindsTheWithClauseAndMakesTheTargetVisiblecallsMutationScopeTest::testReturningIsNullWithoutColumnsAndProjectsTheTargetOtherwisecalls
Relations§
Instantiated in 4
- new SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:54
- new SqlSemantics\Platform\Sqlite\Rules\Mutation\TriggerFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/TriggerFacts.php:65
- new SqlSemantics\Platform\Sqlite\Statement\Mutation\Delete::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Delete.php:73
- new SqlSemantics\Platform\Sqlite\Statement\Mutation\Update::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Update.php:105
Method calls 10
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:55
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:59
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:81
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:90
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\TriggerFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/TriggerFacts.php:65
- method-call SqlSemantics\Platform\Sqlite\Statement\Mutation\Delete::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Delete.php:74
- method-call SqlSemantics\Platform\Sqlite\Statement\Mutation\Delete::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Delete.php:79
- method-call SqlSemantics\Platform\Sqlite\Statement\Mutation\Update::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Update.php:106
- method-call SqlSemantics\Platform\Sqlite\Statement\Mutation\Update::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Update.php:109
- method-call SqlSemantics\Platform\Sqlite\Statement\Mutation\Update::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Update.php:115