classRadixLiteral
final class RadixLiteral
implements Scalar
uses Snapshot
@visibility public.A hexadecimal or bit-value literal: its exact digits and its optional character set introducer.
X'1F' and 0x1F are one literal, as are b'101' and 0b101; the spelling is not kept by the literal (an unaliased select list item, which MySQL names after its text, keeps it in its layout). The digits are kept exactly, leading zeros included.
Rule: MYSQL-RADIX-LITERAL-001. Facts: by default a binary string, VARBINARY; with an introducer a character string, VARCHAR, of the introduced character set; never NULL. In a numeric context the server converts the value, which is a rule of the operator, not of the literal. Precision: the type family is exact; the length is not derived. Diagnostics: none. Source: https://dev.mysql.com/doc/refman/8.4/en/hexadecimal-literals.html, https://dev.mysql.com/doc/refman/8.4/en/bit-value-literals.html. Status: Implemented.
$semantics = new \SqlSemantics\Platform\MySql\Semantics();
[$semantics->analyze("SELECT a FROM t WHERE a = X'1F'")->statement->where->right->digits, $semantics->analyze('SELECT a FROM t WHERE a = 0x1F')->toString()] // => ['1F', "SELECT a FROM t WHERE a = x'1F'"]Properties§
public Radix $radixpublic string $digitspublic Name|null $introducer = nullMethods§
public function __construct(
public Radix $radix,
public string $digits,
public Name|null $introducer = null,
)Parameters
Calls 5
- static-call Check::input() line 58
- function-call
preg_matchline 58 - class-const Radix::Hexadecimal() line 58
- method-call Introducers::known() line 59
- new Introducers line 59
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the string type; a literal is never NULL.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 9
- new Binary line 68
- class-const BinaryKind::VarBinary() line 68
- new Character line 69
- class-const CharacterKind::VarChar() line 69
- new CharsetAttribute line 69
- class-const CharsetForm::Named() line 69
- new ScalarFact line 71
- new Known line 71
- class-const Nullability::NotNull() line 71
public function render(Output $out): voidWrites the introducer and the digits in a spelling that reads back as the same digits.
Parameters
$out | Output |
Calls 5
- method-call Output::spelled() line 80
- class-const Radix::Hexadecimal() line 82
- method-call RadixSpelling::hexadecimal() line 82
- new RadixSpelling line 82
- method-call RadixSpelling::bits() line 82
Test cases 14§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
RadixLiteralTest::testDeriveScalarAnswersVarBinaryWithoutAnIntroducercallsRadixLiteralTest::testDeriveScalarAnswersVarCharOfTheIntroducedCharacterSetcallsRadixLiteralTest::testRejectsAnUnknownIntroducercallsRadixLiteralTest::testRejectsAnUpperCaseIntroducercallsRadixLiteralTest::testRejectsDigitsOutsideTheBitSystemcallsRadixLiteralTest::testRejectsDigitsOutsideTheHexadecimalSystemcallsRadixLiteralTest::testRenderPrefixesAnOddCountOfHexadecimalDigitscallsRadixLiteralTest::testRenderQuotesBitDigitsOfEitherSpellingcalls
Other tests reaching this symbol 6
LiteralRuleTest::testConstantLowersIntroducedRadixLiteralsAndSignedNumberscallsLiteralRuleTest::testLiteralLowersEveryLiteralFormcallsNumericContextTest::testClassifyFollowsTheTypeAndTreatsAHexadecimalLiteralAsAnUnsignedIntegercallsNumericResultTest::testBitsIgnoreAHexadecimalLiteralcallsItemNamingTest::testConstantSpellsTheNameArgumentOfNameConstcallsConcatenationTest::testDeriveScalarIsABinaryStringWhenAnOperandIscalls
Relations§
Instantiated in 4
- new SqlSemantics\Platform\MySql\Lowering\Leaf\LiteralRule::constant() packages/sql-semantics-mysql/src/Lowering/Leaf/LiteralRule.php:153
- new SqlSemantics\Platform\MySql\Lowering\Leaf\LiteralRule::constant() packages/sql-semantics-mysql/src/Lowering/Leaf/LiteralRule.php:154
- new SqlSemantics\Platform\MySql\Lowering\Leaf\LiteralRule::constant() packages/sql-semantics-mysql/src/Lowering/Leaf/LiteralRule.php:155
- new SqlSemantics\Platform\MySql\Lowering\Leaf\LiteralRule::constant() packages/sql-semantics-mysql/src/Lowering/Leaf/LiteralRule.php:156
Type checks 3
- instanceof SqlSemantics\Platform\MySql\Rules\Expression\NumericContext::classify() packages/sql-semantics-mysql/src/Rules/Expression/NumericContext.php:47
- instanceof SqlSemantics\Platform\MySql\Rules\Expression\NumericResult::bits() packages/sql-semantics-mysql/src/Rules/Expression/NumericResult.php:120
- instanceof SqlSemantics\Platform\MySql\Rules\Query\ItemNaming::constant() packages/sql-semantics-mysql/src/Rules/Query/ItemNaming.php:165