classColumnDefinition
final class ColumnDefinition
implements Node
uses Snapshot
@visibility public.One column of a table definition: its name, its declared type and its constraints in written order.
Rule: SQLITE-COLUMN-DEFINITION-001. The declared type is optional and is kept word by word with its quoting, because SQLite records the written text. The constraints are a list in written order; nothing limits how often a kind of constraint occurs. The numbers written as type arguments and the operands of the constraints are derived inside the table definition. Diagnostics: a DEFAULT expression that is not constant (SQLITE-DEFINITION-LIMITS-001), and a DEFAULT on a generated column. Source: https://sqlite.org/syntax/column-def.html, https://sqlite.org/lang_createtable.html#the_default_clause, https://sqlite.org/gencol.html#limitations. Status: Implemented.
$create = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE t (price DECIMAL(10, 2) NOT NULL DEFAULT 0)');
$column = $create->statement->columns[0];
[$column->name->value, $column->type?->text(), count($column->constraints), $column->notNull()] // => ['price', 'DECIMAL', 2, true]Properties§
public list<ColumnConstraint> $constraintspublic Name $namepublic TypeName|null $type = nullMethods§
public function __construct(
public Name $name,
public TypeName|null $type = null,
list<ColumnConstraint> $constraints = [],
)Parameters
$name | Name | The column name |
$type | TypeName|null | The declared type |
$constraints | list<ColumnConstraint> | The constraints in written order |
Calls 2
- static-call Check::listOf() line 57
- class-const ColumnConstraint::class() line 57
public function notNull(): boolTells whether a NOT NULL constraint is written for the column.
Returns
boolTest cases 1
Called from 2
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::slot() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:85
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::added() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:117
public function primaryKey(): ?ColumnPrimaryKeyAnswers the first PRIMARY KEY constraint written for the column.
Returns
Test cases 1
public function generated(): ?GeneratedAnswers the first generated column expression written for the column.
Returns
Test cases 1
Called from 3
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::added() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:112
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::added() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:116
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\Column\ColumnDefinition::deriveColumn() packages/sql-semantics-sqlite/src/Statement/Schema/Column/ColumnDefinition.php:118
public function deriveColumn(Derivation $derivation, ConstraintScope $scope): voidDerives the type arguments and the operands of the constraints inside the table definition, and reports a default SQLite rejects.
Parameters
$derivation | Derivation | |
$scope | ConstraintScope |
Called from 1
Calls 8
- method-call Derivation::scalar() line 108
- method-call Limits::nonConstant() line 113
- new Limits line 113
- method-call Derivation::report() line 114
- new DefaultNotConstant line 114
- method-call ColumnDefinition::generated() line 118
- new GeneratedColumnProblem line 119
- class-const GeneratedColumnFlaw::WithDefault() line 119
public function render(Output $out): voidWrites the name, the declared type and the constraints.
Parameters
$out | Output |
Calls 3
- method-call Output::name() line 128
- class-const NameUse::Column() line 128
- method-call Output::node() line 130
Test cases 7§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 3
Relations§
Instantiated in 1
Method calls 6
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::slot() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:85
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::added() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:112
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::added() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:114
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::added() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:116
- method-call SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems::added() packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:117
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\AlterAddColumn::deriveStatement() packages/sql-semantics-sqlite/src/Statement/Schema/AlterAddColumn.php:73
Constant reads 1
Type declarations 4
- type SqlSemantics\Platform\Sqlite\Lowering\Definition\ColumnRule packages/sql-semantics-sqlite/src/Lowering/Definition/ColumnRule.php:62
- type SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:80
- type SqlSemantics\Platform\Sqlite\Rules\Definition\AlterationProblems packages/sql-semantics-sqlite/src/Rules/Definition/AlterationProblems.php:92
- type SqlSemantics\Platform\Sqlite\Statement\Schema\AlterAddColumn packages/sql-semantics-sqlite/src/Statement/Schema/AlterAddColumn.php:57