final class ViewColumns
Restricted visibility: declared "@visibility SqlSemantics\Platform\MySql". Code outside that scope must not name this declaration.

Derives the column names of a view without a column list from the select list of its first query block.

Rule: MYSQL-VIEW-COLUMNS-001. A column is named like the output field of its query (MYSQL-SELECT-ITEM-NAME-001), with two corrections the server makes for the names it generated, that is for the items that have no alias and are not column references. First a generated name that is not a valid column name (empty, ending in a space character, or longer than 64 characters) becomes Name_exp_N, N being the position of the field (make_valid_column_names). Then, going through the fields in order, a field whose name equals the name of an earlier field (without regard to ASCII case) is renamed when its own name is generated, else the earlier field is when its name is generated; the new name is the original name with the prefix Name_exp_ (My_exp_ in 5.6 and 5.7), and with the prefix and a counter (Name_exp_1_, Name_exp_2_, …) when that name is taken by a field up to the current one, cut to 64 characters (to 191 bytes in 5.6 and 5.7) (check_duplicate_names, make_unique_view_field_name). Two equal names that are not generated are left for MYSQL-TABLE-PROBLEMS-001 to report. A field whose name is not fixed keeps no name. Terminates: each renaming loop stops at the first counter whose name is free, and at most one name per field precedes it. Source: sql/sql_view.cc of each release, https://dev.mysql.com/doc/refman/8.4/en/create-view.html. Status: Implemented.

Methods§

public function __construct(private LanguageProfile $profile, private Comparison $names)

Parameters

$profileLanguageProfileThe profile whose release the names follow
$namesComparisonThe comparison of column names
public function names(Query $query, list<Field> $fields): list<Name|null>

Answers the name of each view column, null when it is not fixed.

Parameters

$queryQuery
$fieldslist<Field>The output fields of the query, in order

Returns

list<Name|null>
Called from 1
Calls 9
public function generated(Query $query, list<Field> $fields): list<bool>

Tells for each field whether the server generated its name: an item without alias that is not a column reference.

Parameters

$queryQuery
$fieldslist<Field>

Returns

list<bool>
Test cases 1
Called from 1
Calls 4
public function block(Query $query): ?Select

Answers the first query block of a query, whose select list names the columns, or null when the query starts with VALUES or TABLE.

Parameters

$queryQuery

Returns

Test cases 1
Called from 1
public function unique(
    array<int, string|null> $names,
    int $renamed,
    int $current,
    string $original,
): string

Answers the name a renamed field gets: the prefix and the original name, with a counter when that name is taken by a field up to the current one.

Parameters

$namesarray<int, string|null>The names so far
$renamedint
$currentint
$originalstring

Returns

string
Test cases 1
Called from 1
Calls 4
public function cut(string $name, bool $legacy): string

Cuts a generated name to the length the release keeps: 64 characters, or 191 bytes in 5.6 and 5.7.

Parameters

$namestring
$legacybool

Returns

string
Test cases 1
Called from 1
Calls 6

Private surface 2§

Implementation details, listed for orientation only.

private LanguageProfile $profile
private Comparison $names

Test cases 4§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 4

Relations§

Instantiated in 1
Method calls 1