classCheckConstraint
final class CheckConstraint
implements TableElement, ColumnAttribute
uses Snapshot
@visibility public.A CHECK constraint, as a table element or as a column attribute.
Rule: MYSQL-CHECK-CONSTRAINT-001. The condition sees the columns of the table (MYSQL-DEFINITION-SCOPE-001). MySQL 8.0.16 and later enforce the constraint unless NOT ENFORCED is written; earlier releases parse and ignore it. A table element carries its ENFORCED clause; a column attribute has none of its own, because the server reads ENFORCED after it as a separate attribute (EnforcementAttribute). Source: https://dev.mysql.com/doc/refman/8.4/en/create-table-check-constraints.html. Status: Implemented.
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE TABLE t (a INT, CONSTRAINT positive CHECK (a > 0) NOT ENFORCED)');
[$create->statement->elements[1]->name->name->column->value, $create->statement->elements[1]->enforced] // => ['positive', false]Properties§
public Scalar $conditionpublic ConstraintName|null $name = nullpublic bool|null $enforced = nullMethods§
public function __construct(
public Scalar $condition,
public ConstraintName|null $name = null,
public bool|null $enforced = null,
)Parameters
$condition | Scalar | The condition every row must not make false |
$name | ConstraintName|null | The CONSTRAINT clause, when written |
$enforced | bool|null | Whether ENFORCED (true) or NOT ENFORCED (false) is written after a table constraint; null when absent |
public function deriveElement(Derivation $derivation, Environment $scope): voidDerives the condition inside the table definition.
Parameters
$derivation | Derivation | |
$scope | Environment |
Test cases 1
Calls 1
- method-call Derivation::scalar() line 49
public function deriveAttribute(Derivation $derivation, Environment $scope): voidDerives the condition inside the table definition.
Parameters
$derivation | Derivation | |
$scope | Environment |
Calls 1
- method-call Derivation::scalar() line 57
public function render(Output $out): voidWrites the constraint name, the condition and the enforcement.
Parameters
$out | Output |
Calls 2
- method-call Output::node() line 65
- method-call Output::keyword() line 67
Test cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
Other tests reaching this symbol 4
Relations§
Instantiated in 4
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\Column\AttributeRule::valued() packages/sql-semantics-mysql/src/Lowering/TableDefinition/Column/AttributeRule.php:121
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\Key\KeyRule::element() packages/sql-semantics-mysql/src/Lowering/TableDefinition/Key/KeyRule.php:77
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\Key\KeyRule::element() packages/sql-semantics-mysql/src/Lowering/TableDefinition/Key/KeyRule.php:78
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\Key\KeyRule::optionalCheck() packages/sql-semantics-mysql/src/Lowering/TableDefinition/Key/KeyRule.php:187