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

Derives the output name of a select list item.

Rule: MYSQL-SELECT-ITEM-NAME-001. An alias names the item. Otherwise an item that names itself keeps its own name, also in parentheses or after a unary plus, which create no item in the server: a column reference is named by its column name as written; a string literal by the decoded value of its first quoted part; NULL by NULL; ? by ?; an integer or floating-point number by its text (at most 256 bytes) and a decimal number by its full text; in 5.6 and 5.7 TRUE and FALSE by TRUE and FALSE; NAME_CONST by the value of its name argument as text. Any other item is named after the text of its expression as the statement writes it: the text of its layout (MYSQL-ITEM-LAYOUT-001), or, for an item without one, the canonical rendering of its expression, which is the text the server then receives; an item has a layout only when it is named after a text other than the canonical rendering. The text ends where the last token of the expression ends (get_cpp_tok_end() in 5.6 and 5.7, the end of the expression's cpp location in 8.0 and later), so whitespace and comments after the expression are never part of the name and an item layout has no trailing trivia (1+1 followed by a comment is named 1+1 in every release, verified on live servers). The server removes the leading characters that are not graphic from the text (Name_string::copy; for binary every byte outside ASCII is not graphic), converts it from the character set it is read in to the system character set (utf8mb3), and keeps at most 255 bytes, 256 when the text is already in that character set (utf8mb3 and national strings, cut at a byte). A text of ASCII characters is therefore its own name when it is short enough, assuming an ASCII-compatible character_set_client; a text read in character_set_client with other characters, or longer than 255 bytes, depends on the session state character_set_client. Binary text keeps its bytes; utf8mb4 text keeps whole characters up to 255 bytes, each character outside utf8mb3 written ?. The name of text with other characters in another introduced character set, and of any text in ucs2, utf16, utf16le or utf32, depends on the server's conversion (NameConversion). Verified on live servers of each release. Source: sql/parse_tree_items.cc (PTI_expr_with_alias::itemize), sql/sql_yacc.yy (select_item), sql/item.cc and sql/item.h (the constructors that set item_name) of each release, https://dev.mysql.com/doc/refman/8.4/en/select.html, https://dev.mysql.com/doc/refman/8.4/en/problems-with-alias.html. Status: Implemented.

Methods§

public function __construct(private LanguageProfile $profile)

Parameters

$profileLanguageProfileThe profile whose release and codec the name follows
public function name(SelectExpression $item): Name|MissingInput

Answers the output name of an item, or the input its name depends on.

An item keeps a layout only where the server names it after its text and the text is not the canonical rendering, as lowering builds it; another layout is an invalid construction.

Parameters

Throws

ImplementationGap When NAME_CONST names the column after a value this rule does not spell
InvalidConstruction When an item that names itself has a layout, or a layout spells the canonical rendering
Test cases 4
Called from 1
Calls 5
public function own(Scalar $expression): ColumnUse|Name|array{string, string}|null
public function constant(Scalar $argument): string

Answers the value of the name argument of NAME_CONST as the server converts it to text.

Parameters

$argumentScalar

Returns

string

Throws

ImplementationGap When the argument is a value this rule does not spell
Test cases 2
Called from 1
Calls 11
public function bytes(string $bits): string

Answers the bytes a bit value holds, padded on the left to whole bytes.

Parameters

$bitsstring

Returns

string
Test cases 1
Called from 1
Calls 7
public function text(SelectExpression $item): string

Answers the text an item is named after: its layout, or the canonical rendering of its expression.

Parameters

Returns

string
Test cases 1
Called from 1
Calls 1
public function stored(string $text, string $charset): Name|MissingInput

Answers the name the server stores for a text read in a character set, or the input it depends on.

The character set is client for character_set_client, national for a national string, else the introduced character set in lower case.

Parameters

$textstring
$charsetstring
Test cases 1
Called from 1
Calls 11
public function narrowed(string $text): Name|NameConversion

Answers the name of a utf8mb4 text: each character outside utf8mb3 becomes ?, and whole characters are kept up to 255 bytes.

Parameters

$textstring
Test cases 1
Called from 1
Calls 6
public function legacy(): bool

Tells whether the release reads TRUE and FALSE as integers named TRUE and FALSE.

Returns

bool
Test cases 1
Called from 1
Calls 2

Private surface 3§

Implementation details, listed for orientation only.

private const LIMITS = ['convert' => 255, 'same' => 256]
private const WIDE = ['ucs2', 'utf16', 'utf16le', 'utf32']
private LanguageProfile $profile

Test cases 13§

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

Dedicated tests 13

Relations§

Instantiated in 4
Method calls 5