classColumnChanges
final class ColumnChanges
Applies the column actions of one ALTER TABLE to the row shape of its table.
Rule: MYSQL-COLUMN-CHANGES-001. The server applies the actions to the existing table as a whole: DROP COLUMN, CHANGE, MODIFY and RENAME COLUMN name a column of the existing table, each such column at most once; ALTER COLUMN names a column of the existing table or one the statement adds; ADD COLUMN adds at the end, FIRST or AFTER a column of the result. The resulting shape is the existing slots without the dropped ones, a renamed slot under its new name re-exposing the existing slot, a changed slot replaced by the declared type and NULL fact of its new definition (MYSQL-COLUMN-DEFINITION-001 through ElementFacts::declaration), and the added columns; a shape that was open stays open. An invisible column (an implicit column of the declaration that aliases no declared column, an added or changed column declared INVISIBLE, or one that ALTER COLUMN … SET INVISIBLE hides) takes part in every check but is found only by name, as an implicit slot, and is not in the row shape. When the table is a declaration with a complete column list, a named column that is not there (or no longer there) is the diagnostic UnknownColumn and a name the result has twice is the diagnostic DuplicateColumn, reported at its later occurrence; nothing is reported for an open shape. Column names compare by the context's column name comparison. Terminates: one pass over the actions, each scanning the finite column list. Source: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html, https://github.com/mysql/mysql-server/blob/mysql-8.4.7/sql/sql_table.cc (mysql_prepare_alter_table). Status: Implemented.
Methods§
public function apply(
RelationFact $table,
list<AlterCommand> $commands,
Derivation $derivation,
bool $report,
): RowShapeAnswers the row shape of the visible columns after the actions, and reports the column problems of a completely known table when asked to.
Parameters
$table | RelationFact | |
$commands | list<AlterCommand> | The actions in order |
$derivation | Derivation | |
$report | bool | Whether to report the column problems |
Returns
Called from 2
- method-call SqlSemantics\Platform\MySql\Statement\Alter\AlterTable::deriveStatement() packages/sql-semantics-mysql/src/Statement/Alter/AlterTable.php:90
- method-call SqlSemantics\Platform\MySql\Statement\Alter\AlterTable::deriveRelation() packages/sql-semantics-mysql/src/Statement/Alter/AlterTable.php:104
Calls 7
- function-call
in_arrayline 100 - new OutputSlot line 101
- new Known line 101
- function-call
countline 101 - method-call ColumnChanges::command() line 107
- method-call ColumnChanges::duplicates() line 109
- new RowShape line 117
public function implicit(): list<ImplicitSlot>Answers the invisible columns after the actions, which a name finds but a star does not.
Returns
list<ImplicitSlot>Called from 1
Calls 1
- new ImplicitSlot line 130
public function command(AlterCommand $command, list<Name> $added): list<Name>Applies one action and answers the names of the columns it adds.
Parameters
$command | AlterCommand | |
$added | list<Name> | The names of the columns the earlier actions added |
Returns
list<Name>Called from 1
Calls 9
- method-call ColumnChanges::insert() line 146
- method-call ColumnChanges::slot() line 146
- method-call ColumnChanges::invisible() line 146
- method-call ColumnChanges::change() line 162
- class-const ElementKind::Column() line 163
- method-call ColumnChanges::drop() line 164
- method-call ColumnChanges::rename() line 166
- method-call ColumnChanges::altered() line 168
- method-call ColumnChanges::show() line 171
public function change(ChangeColumn $command): voidReplaces the existing column a CHANGE or MODIFY names by its new definition.
Parameters
$command | ChangeColumn |
Called from 1
Calls 7
- method-call ColumnChanges::use() line 182
- method-call ChangeColumn::changed() line 182
- method-call ColumnChanges::index() line 183
- function-call
array_spliceline 185 - method-call ColumnChanges::insert() line 187
- method-call ColumnChanges::slot() line 187
- method-call ColumnChanges::invisible() line 187
public function drop(Name $column): voidRemoves the existing column a DROP COLUMN names.
Parameters
$column | Name |
Called from 1
Calls 3
- method-call ColumnChanges::use() line 195
- method-call ColumnChanges::index() line 196
- function-call
array_spliceline 198
Gives the existing column a RENAME COLUMN names its new name.
Called from 1
Calls 3
- method-call ColumnChanges::use() line 207
- method-call ColumnChanges::index() line 208
- new OutputSlot line 211
Reports an ALTER COLUMN of a name that is neither an existing nor an added column.
Called from 2
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::command() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:168
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::command() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:170
Calls 2
- method-call ColumnChanges::find() line 222
- method-call ColumnChanges::unknown() line 223
public function use(Name $column): ?intMarks the existing column of a name as used and answers its position, reporting a name that is absent or already used.
Parameters
$column | Name |
Returns
?intCalled from 3
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::change() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:182
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::drop() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:195
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::rename() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:207
Calls 2
- method-call ColumnChanges::find() line 232
- method-call ColumnChanges::unknown() line 234
Answers the position of a name in a list of names.
Returns
?intCalled from 5
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::altered() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:222
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::use() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:232
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::insert() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:286
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::show() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:304
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::duplicates() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:335
public function index(int $existing): ?intAnswers the index in the result of the column that continues an existing column.
Parameters
$existing | int |
Returns
?intTest cases 1
Called from 3
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::change() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:183
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::drop() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:196
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::rename() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:208
public function insert(
OutputSlot $slot,
?ColumnPosition $position,
?int $index,
bool $hidden,
): voidPlaces a column of the result: FIRST, AFTER a column of the result, at an index, or last.
Parameters
$slot | OutputSlot | |
$position | ?ColumnPosition | |
$index | ?int | |
$hidden | bool |
Called from 3
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::command() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:146
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::command() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:154
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::change() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:187
Calls 4
- method-call ColumnChanges::find() line 286
- method-call ColumnChanges::unknown() line 288
- function-call
array_spliceline 292 - function-call
countline 292
public function show(ColumnVisibility $command): voidMakes the columns an ALTER COLUMN … SET VISIBLE or INVISIBLE names visible or invisible.
Parameters
$command | ColumnVisibility |
Called from 1
Calls 1
- method-call ColumnChanges::find() line 304
public function invisible(ColumnDefinition $definition): boolTells whether a new column definition is INVISIBLE.
Parameters
$definition | ColumnDefinition |
Returns
boolCalled from 3
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::command() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:146
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::command() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:154
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::change() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:187
Calls 2
- method-call ColumnFlags::invisible() line 315
- new ColumnFlags line 315
public function slot(ColumnDefinition $definition): OutputSlotAnswers the slot of a new column definition.
Parameters
$definition | ColumnDefinition |
Returns
Called from 3
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::command() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:146
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::command() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:154
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::change() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:187
Calls 4
- method-call ElementFacts::declaration() line 323
- new ElementFacts line 323
- new OutputSlot line 325
- new Known line 325
public function duplicates(): voidReports each name the result has a second time.
Called from 1
Calls 3
- method-call ColumnChanges::find() line 335
- method-call ColumnChanges::report() line 336
- new DuplicateColumn line 336
public function unknown(Name $column): voidReports an absent column name.
Parameters
$column | Name |
Called from 3
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::altered() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:223
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::use() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:234
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::insert() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:288
Calls 2
- method-call ColumnChanges::report() line 347
- new UnknownColumn line 347
public function report(UnknownColumn|DuplicateColumn $problem): voidReports a problem when the table is completely known.
Parameters
$problem | UnknownColumn|DuplicateColumn |
Called from 2
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::duplicates() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:336
- method-call SqlSemantics\Platform\MySql\Rules\TableChange\ColumnChanges::unknown() packages/sql-semantics-mysql/src/Rules/TableChange/ColumnChanges.php:347
Private surface 6§
Implementation details, listed for orientation only.
private list<array{OutputSlot, int|null, bool}> $columns = []private array<int, true> $used = []private list<Name|null> $existing = []private bool $decided = falseprivate bool $reporting = falseprivate ?Derivation $derivation = nullTest cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
Relations§
Instantiated in 2
Method calls 3
- method-call SqlSemantics\Platform\MySql\Statement\Alter\AlterTable::deriveStatement() packages/sql-semantics-mysql/src/Statement/Alter/AlterTable.php:90
- method-call SqlSemantics\Platform\MySql\Statement\Alter\AlterTable::deriveStatement() packages/sql-semantics-mysql/src/Statement/Alter/AlterTable.php:91
- method-call SqlSemantics\Platform\MySql\Statement\Alter\AlterTable::deriveRelation() packages/sql-semantics-mysql/src/Statement/Alter/AlterTable.php:104