classGenerated
final class Generated
implements ColumnConstraint
uses Snapshot
@visibility public.A generated column constraint: the expression that computes the column.
Rule: SQLITE-COLUMN-GENERATED-001. The expression may refer to the other columns of the table and "may not directly reference the ROWID"; it is derived at a position that sees the columns of the table being defined only. A bound parameter, a subquery, a qualified column reference or a non-deterministic function in it is a diagnostic (SQLITE-DEFINITION-LIMITS-001). The keywords GENERATED ALWAYS are optional: the parser reads them as words of the declared type, exactly as SQLite's parser does, and the declared type drops them again (SQLITE-TYPE-RECORDING-001), so the constraint itself writes only AS. The grammar accepts any identifier after the expression; SQLite compares its written text with virtual and stored and rejects every other word, so the word is kept with its quoting and an unknown one is a diagnostic. A column without the word is VIRTUAL. Source: https://sqlite.org/gencol.html. Status: Implemented.
$create = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE t (a, b GENERATED ALWAYS AS (a + 1) VIRTUAL)');
[$create->statement->columns[1]->constraints[0]->storage(), $create->toString()] // => [\SqlSemantics\Platform\Sqlite\Statement\Schema\Column\GeneratedStorage::Virtual, 'CREATE TABLE t (a, b GENERATED ALWAYS AS (a + 1) VIRTUAL)']Properties§
public Scalar $expressionpublic Word|null $word = nullMethods§
public function __construct(public Scalar $expression, public Word|null $word = null)Parameters
$expression | Scalar | The expression that computes the column |
$word | Word|null | The word written after the expression |
Calls 2
- static-call Check::input() line 52
- class-const WordQuote::Single() line 52
public function storage(): ?GeneratedStorageAnswers how the column is stored, or null when the written word is neither VIRTUAL nor STORED.
Returns
Test cases 2
Called from 1
Calls 2
- class-const GeneratedStorage::Virtual() line 61
- class-const GeneratedStorage::Stored() line 64
public function deriveConstraint(Derivation $derivation, ConstraintScope $scope): voidDerives the expression where the columns of the table are visible and reports an unknown storage word.
Parameters
$derivation | Derivation | |
$scope | ConstraintScope |
Calls 7
- method-call Derivation::scalar() line 72
- method-call Limits::report() line 73
- new Limits line 73
- class-const DefinitionPosition::GeneratedColumn() line 73
- method-call Generated::storage() line 74
- method-call Derivation::report() line 75
- new UnknownStorage line 75
public function render(Output $out): voidWrites the clause without the optional GENERATED ALWAYS keywords.
Parameters
$out | Output |
Calls 1
- method-call Output::keyword() line 84
Test cases 7§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.