classColumnRule
final class ColumnRule
Lowers column specifications: the data type, the attributes and the generation expression of a column.
Rule: MYSQL-COLUMN-SPECIFICATION-001. Scope: field_def, opt_attribute, opt_attribute_list, opt_column_attribute_list, column_attribute_list, opt_gcol_attribute_list, gcol_attribute_list, opt_generated_always, opt_stored_attribute, generated_column_func, parse_gcol_expr. MySQL 5.6 writes the type and the attributes directly in field_spec. A CHECK clause after a 5.x column definition is the last attribute; an inline REFERENCES clause is the reference of the specification. GENERATED ALWAYS is optional and not kept. The parser of MySQL 8.0 and later reads every column attribute after a generation expression and then refuses DEFAULT, ON UPDATE, AUTO_INCREMENT, SERIAL DEFAULT VALUE, COLUMN_FORMAT and STORAGE there, and the type SERIAL, with ER_WRONG_USAGE ("Incorrect
- usage of DEFAULT and generated column"; sql/parse_tree_column_attrs.h
PT_default_column_attr::do_contextualize and its siblings, PT_generated_field_def_base); 5.7 has no grammar for them. Constructs: OrdinaryColumn, GeneratedColumn, ParseGeneratedColumn. Terminates: lists are flattened iteratively. Source: https://dev.mysql.com/doc/refman/8.4/en/create-table.html, https://dev.mysql.com/doc/refman/8.4/en/create-table-generated-columns.html. Status: Implemented.
Methods§
public function __construct(private Lowering $lowering)Parameters
$lowering | Lowering | The lowering this rule belongs to |
public function specification(
Node $definition,
?Node $attributes = null,
?References $references = null,
list<ColumnAttribute> $trailing = [],
): ColumnSpecificationLowers a column specification: a node of field_def, or the nodes of type and opt_attribute (5.6).
Parameters
$definition | Node | |
$attributes | ?Node | |
$references | ?References | |
$trailing | list<ColumnAttribute> | Attributes written after the specification, such as a 5.x column CHECK |
Returns
Throws
ImplementationGap When a production has no ruleAnalysisException When a generated column has an attribute or type the server refuses for itTest cases 3
Called from 5
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\ElementRule::element() packages/sql-semantics-mysql/src/Lowering/TableDefinition/ElementRule.php:97
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\ElementRule::column() packages/sql-semantics-mysql/src/Lowering/TableDefinition/ElementRule.php:118
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\ElementRule::column() packages/sql-semantics-mysql/src/Lowering/TableDefinition/ElementRule.php:119
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\TableDefinitionRules::columnSpecification() packages/sql-semantics-mysql/src/Lowering/TableDefinition/TableDefinitionRules.php:121
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\TableDefinitionRules::columnSpecification() packages/sql-semantics-mysql/src/Lowering/TableDefinition/TableDefinitionRules.php:124
Calls 10
- new OrdinaryColumn line 98
- method-call ColumnRule::attributes() line 98
- static-call ImplementationGap::rule() line 98
- class-const ColumnRule::GENERATED() line 101
- method-call ColumnRule::always() line 104
- method-call ColumnRule::refuse() line 107
- new GeneratedColumn line 109
- method-call ColumnRule::expression() line 111
- method-call ColumnRule::storage() line 113
- static-call ImplementationGap::production() line 121
public function attributes(Node $list): list<ColumnAttribute>Lowers an optional attribute list.
Parameters
$list | Node |
Returns
list<ColumnAttribute>Throws
ImplementationGap When a production has no ruleTest cases 1
Called from 3
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\Column\ColumnRule::specification() packages/sql-semantics-mysql/src/Lowering/TableDefinition/Column/ColumnRule.php:98
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\Column\ColumnRule::specification() packages/sql-semantics-mysql/src/Lowering/TableDefinition/Column/ColumnRule.php:106
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\Column\ColumnRule::specification() packages/sql-semantics-mysql/src/Lowering/TableDefinition/Column/ColumnRule.php:120
Calls 7
- class-const ColumnRule::OPTIONAL() line 134
- static-call ImplementationGap::production() line 134
- new AttributeRule line 137
- method-call Spine::items() line 139
- new Spine line 139
- class-const ColumnRule::LISTS() line 139
- method-call AttributeRule::attribute() line 140
public function refuse(list<ColumnAttribute> $attributes, TypeName $type): voidRefuses, as the server's parser does, the attributes and the type a generated column cannot have.
The first such attribute in written order is named, then the type SERIAL.
Parameters
$attributes | list<ColumnAttribute> | The attributes in written order |
$type | TypeName |
Throws
AnalysisException When the generated column has DEFAULT, ON UPDATE, AUTO_INCREMENT, SERIAL DEFAULT VALUE, COLUMN_FORMAT or STORAGE, or the type SERIALCalled from 1
Calls 4
- class-const ColumnKeyword::AutoIncrement() line 160
- class-const ColumnKeyword::SerialDefaultValue() line 160
- new AnalysisException line 166
- class-const ElementaryKind::Serial() line 169
public function always(Node $words): voidConfirms the optional words GENERATED ALWAYS: a node of opt_generated_always.
Parameters
$words | Node |
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 1
Calls 1
- static-call ImplementationGap::production() line 183
public function storage(Node $storage): ?GeneratedStorageLowers VIRTUAL or STORED: a node of opt_stored_attribute; absent is null.
Parameters
$storage | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 1
Calls 3
- class-const GeneratedStorage::Virtual() line 198
- class-const GeneratedStorage::Stored() line 199
- static-call ImplementationGap::production() line 200
Lowers a generation expression: a node of generated_column_func or expr.
Parameters
$expression | Node |
Returns
Throws
ImplementationGap When a production has no ruleTest cases 1
Called from 2
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\Column\ColumnRule::specification() packages/sql-semantics-mysql/src/Lowering/TableDefinition/Column/ColumnRule.php:111
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\Column\ColumnRule::parse() packages/sql-semantics-mysql/src/Lowering/TableDefinition/Column/ColumnRule.php:234
Calls 1
- static-call ImplementationGap::production() line 216
public function parse(Node $statement): ParseGeneratedColumnLowers the internal 5.7 statement PARSE_GCOL_EXPR: a node of parse_gcol_expr.
Parameters
$statement | Node |
Returns
Throws
ImplementationGap When a production has no ruleTest cases 1
Called from 1
Calls 3
- static-call ImplementationGap::production() line 231
- new ParseGeneratedColumn line 234
- method-call ColumnRule::expression() line 234
Private surface 4§
Implementation details, listed for orientation only.
private const LISTS = ['opt_attribute_list: opt_attribute_list attribute', 'opt_attribute_list: attri…private const OPTIONAL = ['opt_attribute:' => false, 'opt_attribute: opt_attribute_list' => true, 'opt_c…private const GENERATED = ['field_def: type opt_collate_explicit opt_generated_always AS ( generated_colu…private Lowering $loweringTest cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
ColumnRuleTest::testAlwaysAcceptsTheOptionalWordscallsColumnRuleTest::testAttributesLowersTheListInOrdercallsColumnRuleTest::testExpressionLowersAGeneratedColumnFunctioncallsColumnRuleTest::testParseLowersParseGcolExprcallsColumnRuleTest::testSpecificationLowersAGeneratedColumncallsColumnRuleTest::testSpecificationLowersALegacyTypeAndAttributescallsColumnRuleTest::testSpecificationRefusesAnAttributeOfAGeneratedColumncallsColumnRuleTest::testStorageLowersVirtualAndStoredcalls
Relations§
Instantiated in 4
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\ElementRule::element() packages/sql-semantics-mysql/src/Lowering/TableDefinition/ElementRule.php:97
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\ElementRule::column() packages/sql-semantics-mysql/src/Lowering/TableDefinition/ElementRule.php:114
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\TableDefinitionRules::statement() packages/sql-semantics-mysql/src/Lowering/TableDefinition/TableDefinitionRules.php:55
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\TableDefinitionRules::columnSpecification() packages/sql-semantics-mysql/src/Lowering/TableDefinition/TableDefinitionRules.php:119
Method calls 6
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\ElementRule::element() packages/sql-semantics-mysql/src/Lowering/TableDefinition/ElementRule.php:97
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\ElementRule::column() packages/sql-semantics-mysql/src/Lowering/TableDefinition/ElementRule.php:118
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\ElementRule::column() packages/sql-semantics-mysql/src/Lowering/TableDefinition/ElementRule.php:119
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\TableDefinitionRules::statement() packages/sql-semantics-mysql/src/Lowering/TableDefinition/TableDefinitionRules.php:55
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\TableDefinitionRules::columnSpecification() packages/sql-semantics-mysql/src/Lowering/TableDefinition/TableDefinitionRules.php:121
- method-call SqlSemantics\Platform\MySql\Lowering\TableDefinition\TableDefinitionRules::columnSpecification() packages/sql-semantics-mysql/src/Lowering/TableDefinition/TableDefinitionRules.php:124