classItemNaming
final class ItemNaming
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
$profile | LanguageProfile | The profile whose release and codec the name follows |
public function name(SelectExpression $item): Name|MissingInputAnswers 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
$item | SelectExpression |
Returns
Throws
ImplementationGap When NAME_CONST names the column after a value this rule does not spellInvalidConstruction When an item that names itself has a layout, or a layout spells the canonical renderingTest cases 4
Called from 1
Calls 5
- method-call ItemNaming::own() line 111
- static-call Check::input() line 112
- method-call ItemNaming::canonical() line 112
- method-call ItemNaming::stored() line 120
- method-call ItemNaming::text() line 120
Answers the own name of an item that names itself, its text with the character set it is in, or null when the item is named after its written text.
A column reference answers itself: it is named by its column name.
Parameters
$expression | Scalar |
Throws
ImplementationGap When NAME_CONST names the column after a value this rule does not spellTest cases 2
Called from 4
- method-call SqlSemantics\Platform\MySql\Lowering\Query\Shared\ItemRule::expression() packages/sql-semantics-mysql/src/Lowering/Query/Shared/ItemRule.php:177
- method-call SqlSemantics\Platform\MySql\Rules\Query\ItemNaming::name() packages/sql-semantics-mysql/src/Rules/Query/ItemNaming.php:111
- method-call SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::aliases() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:127
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\ViewColumns::generated() packages/sql-semantics-mysql/src/Rules/TableDefinition/ViewColumns.php:116
Calls 6
- class-const UnaryOperator::Plus() line 133
- new Name line 140
- class-const NumberForm::Decimal() line 142
- method-call ItemNaming::legacy() line 143
- function-call
strcasecmpline 144 - method-call ItemNaming::constant() line 144
public function constant(Scalar $argument): stringAnswers the value of the name argument of NAME_CONST as the server converts it to text.
Parameters
$argument | Scalar |
Returns
stringThrows
ImplementationGap When the argument is a value this rule does not spellTest cases 2
Called from 1
Calls 11
- method-call Scalar::value() line 157
- class-const NumberForm::Float() line 159
- function-call
explodeline 160 - function-call
ltrimline 161 - class-const Radix::Hexadecimal() line 166
- function-call
hex2binline 166 - function-call
str_padline 166 - function-call
ceilline 166 - function-call
strlenline 166 - method-call ItemNaming::bytes() line 166
- static-call ImplementationGap::rule() line 171
public function bytes(string $bits): stringAnswers the bytes a bit value holds, padded on the left to whole bytes.
Parameters
$bits | string |
Returns
stringTest cases 1
Called from 1
public function text(SelectExpression $item): stringAnswers the text an item is named after: its layout, or the canonical rendering of its expression.
Parameters
$item | SelectExpression |
Returns
stringTest cases 1
Called from 1
Calls 1
- method-call ItemNaming::canonical() line 192
public function canonical(Scalar $expression): stringAnswers the text an expression is written as without a layout of its own.
Parameters
$expression | Scalar |
Returns
stringTest cases 1
Called from 3
- method-call SqlSemantics\Platform\MySql\Lowering\Query\Shared\ItemRule::expression() packages/sql-semantics-mysql/src/Lowering/Query/Shared/ItemRule.php:178
- method-call SqlSemantics\Platform\MySql\Rules\Query\ItemNaming::name() packages/sql-semantics-mysql/src/Rules/Query/ItemNaming.php:112
- method-call SqlSemantics\Platform\MySql\Rules\Query\ItemNaming::text() packages/sql-semantics-mysql/src/Rules/Query/ItemNaming.php:192
Calls 6
- new Output line 200
- new Codec line 200
- method-call Output::layout() line 201
- method-call Lexical::join() line 203
- new Lexical line 203
- method-call Output::pieces() line 203
public function stored(string $text, string $charset): Name|MissingInputAnswers 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
$text | string | |
$charset | string |
Returns
Test cases 1
Called from 1
Calls 11
- function-call
in_arrayline 214 - class-const ItemNaming::WIDE() line 214
- new NameConversion line 215
- function-call
ltrimline 217 - function-call
preg_matchline 218 - function-call
strlenline 219 - class-const ItemNaming::LIMITS() line 219
- new SessionState line 220
- method-call ItemNaming::narrowed() line 223
- new Name line 230
- function-call
substrline 230
public function narrowed(string $text): Name|NameConversionAnswers the name of a utf8mb4 text: each character outside utf8mb3 becomes ?, and whole characters are kept up to 255 bytes.
Parameters
$text | string |
Returns
Test cases 1
Called from 1
Calls 6
- function-call
mb_check_encodingline 238 - function-call
mb_str_splitline 238 - new NameConversion line 240
- function-call
strlenline 244 - class-const ItemNaming::LIMITS() line 245
- new Name line 251
public function legacy(): boolTells whether the release reads TRUE and FALSE as integers named TRUE and FALSE.
Returns
boolTest cases 1
Called from 1
Calls 2
- class-const GrammarRelease::MySql5651() line 259
- class-const GrammarRelease::MySql5744() line 259
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 $profileTest cases 13§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 13
ItemNamingTest::testBytesPadsBitsToWholeBytescallsItemNamingTest::testCanonicalAnswersTheRenderedTextcallsItemNamingTest::testConstantRefusesAValueItDoesNotSpellcallsItemNamingTest::testConstantSpellsTheNameArgumentOfNameConstcallsItemNamingTest::testLegacyTellsTheReleasesThatNameBooleansInUpperCasecallsItemNamingTest::testNameAnswersTheAliasTheColumnNameOrTheTextcallsItemNamingTest::testNameAnswersTheConversionANonAsciiTextDependsOncallsItemNamingTest::testNameRefusesALayoutOfAnItemThatNamesItselfcallsItemNamingTest::testNameRefusesALayoutThatSpellsTheCanonicalRenderingcallsItemNamingTest::testNarrowedKeepsWholeCharactersOfUtf8mb3callsItemNamingTest::testOwnAnswersTheNamesOfTheItemsThatNameThemselvescallsItemNamingTest::testStoredStripsLeadingControlsAndCapsTheLengthcallsItemNamingTest::testTextAnswersTheLayoutOrTheCanonicalRenderingcalls
Relations§
Instantiated in 4
- new SqlSemantics\Platform\MySql\Lowering\Query\Shared\ItemRule::expression() packages/sql-semantics-mysql/src/Lowering/Query/Shared/ItemRule.php:176
- new SqlSemantics\Platform\MySql\Rules\Query\Projection::items() packages/sql-semantics-mysql/src/Rules/Query/Projection.php:59
- new SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::aliases() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:125
- new SqlSemantics\Platform\MySql\Rules\TableDefinition\ViewColumns::generated() packages/sql-semantics-mysql/src/Rules/TableDefinition/ViewColumns.php:112
Method calls 5
- method-call SqlSemantics\Platform\MySql\Lowering\Query\Shared\ItemRule::expression() packages/sql-semantics-mysql/src/Lowering/Query/Shared/ItemRule.php:177
- method-call SqlSemantics\Platform\MySql\Lowering\Query\Shared\ItemRule::expression() packages/sql-semantics-mysql/src/Lowering/Query/Shared/ItemRule.php:178
- method-call SqlSemantics\Platform\MySql\Rules\Query\Projection::items() packages/sql-semantics-mysql/src/Rules/Query/Projection.php:59
- method-call SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::aliases() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:127
- method-call SqlSemantics\Platform\MySql\Rules\TableDefinition\ViewColumns::generated() packages/sql-semantics-mysql/src/Rules/TableDefinition/ViewColumns.php:116