classGeneratedWrites
final class GeneratedWrites
Reports the writes of generated columns, and counts the columns an INSERT without a column list fills.
Rule: SQLITE-GENERATED-WRITE-001. A generated column, VIRTUAL or STORED, cannot be written. Naming one in the column list of an INSERT is rejected with "cannot INSERT into generated column" (sqlite3Insert() in insert.c); assigning one in UPDATE SET or in DO UPDATE SET is rejected with "cannot UPDATE generated column" (sqlite3Update() in update.c). Both messages name the column as declared. An INSERT without a column list supplies one value per column that is not generated.
SQLite compiles the DO UPDATE of an upsert, and so checks it, only where a uniqueness check of the INSERT selects that clause (sqlite3GenerateConstraintChecks() in insert.c, sqlite3UpsertOfIndex() in upsert.c). The rowid check runs when the row supplies the rowid: the column list names it or the integer primary key, or there is no column list and the table has an integer primary key. It selects the first clause without a conflict target or with the rowid as its target. Every unique index is checked on INSERT and selects the first clause whose target matches it, or else the clause without a target; a conflict target that matches no index is an error of its own. So a DO UPDATE is certainly compiled when it has a target other than the rowid and no earlier clause has one (a later clause for the same index never fires), when the rowid check selects it, and when it is the only clause, has no target and writes a WITHOUT ROWID table, whose primary key is a unique index. Otherwise it depends on the unique indexes of the table, which a declaration does not hold, and no write is reported. Source: https://sqlite.org/gencol.html, https://sqlite.org/lang_insert.html, https://sqlite.org/lang_upsert.html. Status: Implemented.
Methods§
public function writable(RowShape $shape): intAnswers how many columns of a complete row shape an INSERT without a column list fills: those that are not generated.
Parameters
$shape | RowShape |
Returns
intTest cases 1
public function inserted(
list<Name> $columns,
VisibleRelation $target,
Derivation $derivation,
): voidReports each name of an INSERT column list that denotes a generated column of the written table.
Parameters
$columns | list<Name> | |
$target | VisibleRelation | |
$derivation | Derivation |
Called from 1
Calls 4
- method-call GeneratedWrites::written() line 81
- method-call Derivation::report() line 83
- new GeneratedColumnWrite line 83
- class-const WriteKind::Insert() line 83
public function assigned(
list<Assignment|RowAssignment> $assignments,
VisibleRelation $target,
Derivation $derivation,
): voidReports each column of UPDATE SET or DO UPDATE SET that is a generated column of the written table.
Parameters
$assignments | list<Assignment|RowAssignment> | |
$target | VisibleRelation | |
$derivation | Derivation |
Called from 2
Calls 4
- method-call GeneratedWrites::written() line 97
- method-call Derivation::report() line 99
- new GeneratedColumnWrite line 99
- class-const WriteKind::Update() line 99
public function written(Name $name, VisibleRelation $target, Derivation $derivation): ?ColumnAnswers the generated column a written name denotes, or null when it denotes another column or none.
Parameters
$name | Name | |
$target | VisibleRelation | |
$derivation | Derivation |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\GeneratedWrites::inserted() packages/sql-semantics-sqlite/src/Rules/Mutation/GeneratedWrites.php:81
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\GeneratedWrites::assigned() packages/sql-semantics-sqlite/src/Rules/Mutation/GeneratedWrites.php:97
Calls 2
- method-call Joining::locate() line 110
- new Joining line 110
public function reached(
list<Upsert> $upserts,
int $index,
Table $table,
bool $supplied,
Environment $environment,
): boolTells whether SQLite certainly compiles the DO UPDATE of the clause at a position.
Parameters
$upserts | list<Upsert> | The ON CONFLICT clauses in written order |
$index | int | The position of the clause |
$table | Table | The declaration of the written table |
$supplied | bool | Whether the inserted row supplies the rowid |
$environment | Environment | The scope of the conflict targets |
Returns
boolCalled from 1
Calls 5
- method-call GeneratedWrites::rowidTarget() line 131
- function-call
in_arrayline 136 - function-call
array_sliceline 136 - function-call
countline 142 - class-const RelationKind::BaseTable() line 142
public function rowidTarget(
ConflictTarget $target,
Column $rowid,
Environment $environment,
): boolTells whether a conflict target is the rowid: a single term that is a name denoting it, possibly in parentheses.
Parameters
$target | ConflictTarget | |
$rowid | Column | The column the rowid names denote |
$environment | Environment |
Returns
boolTest cases 1
Called from 1
Calls 3
- function-call
countline 152 - method-call ColumnFacts::denoted() line 152
- new ColumnFacts line 152
public function supplied(
list<Name> $columns,
Table $table,
VisibleRelation $target,
Derivation $derivation,
): boolTells whether the inserted row supplies the rowid: through the column list, or by the integer primary key when there is no list.
Parameters
$columns | list<Name> | The column list; empty when none is written |
$table | Table | |
$target | VisibleRelation | |
$derivation | Derivation |
Returns
boolCalled from 1
Calls 4
- function-call
in_arrayline 169 - new Environment line 171
- method-call ColumnResolver::find() line 173
- new ColumnResolver line 173
Test cases 4§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 4
GeneratedWritesTest::testRowidTargetRecognisesASingleNameOfTheRowidcallsGeneratedWritesTest::testSuppliedTellsWhetherTheInsertedRowSuppliesTheRowidcallsGeneratedWritesTest::testWritableCountsTheColumnsThatAreNotGeneratedcallsGeneratedWritesTest::testWrittenAnswersTheGeneratedColumnANameDenotescalls
Relations§
Instantiated in 2
Method calls 6
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:61
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:64
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:72
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:82
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:83
- method-call SqlSemantics\Platform\Sqlite\Statement\Mutation\Update::deriveWithin() packages/sql-semantics-sqlite/src/Statement/Mutation/Update.php:110