classViewColumns
final class ViewColumns
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
$profile | LanguageProfile | The profile whose release the names follow |
$names | Comparison | The comparison of column names |
Answers the name of each view column, null when it is not fixed.
Returns
list<Name|null>Called from 1
Calls 9
- method-call ViewColumns::generated() line 69
- method-call ColumnNameRule::valid() line 74
- new ColumnNameRule line 74
- function-call
array_keysline 80 - method-call Comparison::equal() line 85
- method-call ViewColumns::unique() line 90
- function-call
array_valuesline 95 - function-call
array_mapline 95 - new Name line 95
Tells for each field whether the server generated its name: an item without alias that is not a column reference.
Returns
list<bool>Test cases 1
Called from 1
Calls 4
- method-call ViewColumns::block() line 107
- function-call
spl_object_idline 109 - new ItemNaming line 112
- method-call ItemNaming::own() line 116
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
$query | Query |
Returns
Test cases 1
public function unique(
array<int, string|null> $names,
int $renamed,
int $current,
string $original,
): stringAnswers 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
$names | array<int, string|null> | The names so far |
$renamed | int | |
$current | int | |
$original | string |
Returns
stringTest cases 1
Called from 1
Calls 4
- class-const GrammarRelease::MySql5651() line 151
- class-const GrammarRelease::MySql5744() line 151
- method-call ViewColumns::cut() line 154
- method-call Comparison::equal() line 157
public function cut(string $name, bool $legacy): stringCuts a generated name to the length the release keeps: 64 characters, or 191 bytes in 5.6 and 5.7.
Parameters
$name | string | |
$legacy | bool |
Returns
stringTest cases 1
Called from 1
Calls 6
- function-call
substrline 174 - method-call ColumnNameRule::length() line 177
- new ColumnNameRule line 177
- function-call
implodeline 177 - function-call
array_sliceline 177 - function-call
preg_splitline 177
Private surface 2§
Implementation details, listed for orientation only.
private LanguageProfile $profileprivate Comparison $namesTest cases 4§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.