classStringLiteral
final class StringLiteral
implements Scalar
uses Snapshot
@visibility public.A character string literal: its decoded segments, its optional character set introducer, and whether it is a national string.
Quoted strings written next to each other are one literal whose value is their concatenation; the segments are kept because the server names an unaliased result column after the first one. _charset'text' has the introduced character set, N'text' the national character set. Which quote character was written has no meaning and is not kept.
Rule: MYSQL-STRING-LITERAL-001. Facts: a character string type, VARCHAR, of the introduced character set when there is one and of the national character set for a national string; never NULL. The character set and collation of a plain literal are those of the connection, which a context does not hold, so the type names no character set. Precision: the type family is exact; the length is not derived. Diagnostics: none. A literal spelled under another escape rule than the profile is an invalid construction. Source: https://dev.mysql.com/doc/refman/8.4/en/string-literals.html, https://dev.mysql.com/doc/refman/8.4/en/charset-literal.html. Status: Implemented.
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze("SELECT a FROM t WHERE a = 'x' \"y\"");
[$query->statement->where->right->segments, $query->statement->where->right->value()] // => [['x', 'y'], 'xy']Properties§
public non-empty-list<string> $segmentspublic EscapeRule $escapes = EscapeRule::Backslashpublic Name|null $introducer = nullpublic bool $national = falseMethods§
public function __construct(
array<array-key, string|int|bool|object|null> $segments,
public EscapeRule $escapes = EscapeRule::Backslash,
public Name|null $introducer = null,
public bool $national = false,
)Parameters
$segments | array<array-key, string|int|bool|object|null> | The decoded bytes of each adjacent quoted string, as a list of strings; at least one |
$escapes | EscapeRule | The rule the value is spelled under; the rule of the language profile |
$introducer | Name|null | The introduced character set, in lower case |
$national | bool | Whether the literal is written `N'...'`; excludes an introducer |
Calls 6
- class-const EscapeRule::Backslash() line 63
- static-call Check::input() line 67
- function-call
is_stringline 67 - function-call
array_is_listline 70 - method-call Introducers::known() line 71
- new Introducers line 71
public function value(): stringAnswers the value of the literal: the concatenation of its segments.
Returns
stringCalls 1
- function-call
implodeline 80
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the character string type; a literal is never NULL.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 9
- static-call Check::input() line 88
- static-call EscapeRule::under() line 88
- new CharsetAttribute line 89
- class-const CharsetForm::Named() line 89
- new ScalarFact line 91
- new Known line 91
- new Character line 91
- class-const CharacterKind::VarChar() line 91
- class-const Nullability::NotNull() line 91
public function render(Output $out): voidWrites the introducer or the national prefix and each segment in single quotes.
Parameters
$out | Output |
Calls 4
- new Strings line 99
- method-call Output::spelled() line 101
- method-call Strings::encode() line 104
- class-const EscapeRule::Backslash() line 104
Test cases 82§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 12
StringLiteralTest::testDeriveScalarAnswersTheIntroducedCharacterSetcallsStringLiteralTest::testDeriveScalarAnswersTheNationalCharacterSetcallsStringLiteralTest::testDeriveScalarAnswersVarCharOfNoCharacterSetThatIsNeverNullcallsStringLiteralTest::testDeriveScalarRejectsALiteralSpelledUnderTheOtherEscapeRulecallsStringLiteralTest::testRejectsAKeyedSegmentListcallsStringLiteralTest::testRejectsAnEmptySegmentListcallsStringLiteralTest::testRejectsAnIntroducerOnANationalStringcallsStringLiteralTest::testRejectsAnUnknownIntroducercallsStringLiteralTest::testRejectsASegmentThatIsNoStringcallsStringLiteralTest::testRenderDecodesAndSpellsEscapesUnderTheBackslashRulecallsStringLiteralTest::testRenderKeepsBackslashesUnderTheVerbatimRulecallsStringLiteralTest::testValueConcatenatesTheAdjacentSegmentscalls
Other tests reaching this symbol 70
PredicateRuleTest::testEscapeLowersTheEscapeClauseOfMySql5callsPredicateRuleTest::testMemberLowersMemberWithoutOfcallsPredicateRuleTest::testOperationLowersSoundsLikecallsLiteralRuleTest::testLiteralLowersEveryLiteralFormcallsLiteralRuleTest::testStringLowersAdjacentSegmentsIntroducersAndTheNationalPrefixcallsSignalRuleTest::providerStatementLowersResignalcallsSignalRuleTest::testOperandLowersLiteralsVariablesAndNamescallsEventRuleTest::testBoundLowersStartsAndEndscallsEventRuleTest::testScheduleLowersAtAndEverycallsBlockRuleTest::testDeclarationLowersAVariableWithItsCollationAndDefaultcallsWindowResultsTest::testResultTypesEachKindOfWindowFunctioncallsNumericResultTest::testBeyondComparesWithTheNegatedRangecallsNumericResultTest::testBinaryMakesABitOperationOfBinaryStringsABinaryStringFromMySql80callsNumericResultTest::testBinaryTypesASumOfAnIntegerAndAStringcallsItemNamingTest::testCanonicalAnswersTheRenderedTextcallsItemNamingTest::testConstantSpellsTheNameArgumentOfNameConstcallsItemNamingTest::testNameAnswersTheConversionANonAsciiTextDependsOncallsItemNamingTest::testOwnAnswersTheNamesOfTheItemsThatNameThemselvescallsGroupConcatTest::testDeriveScalarReportsAWindowcallsJsonObjectAggregateTest::testAggregatesTellsWhetherTheCallHasNoWindowcallsJsonObjectAggregateTest::testDeriveScalarAnswersJsoncallsExtractTest::testDeriveScalarAnswersAnIntegercallsFunctionCallTest::testDeriveScalarTypesANativeFunctioncallsJsonValueCallTest::testDeriveScalarAnswersACharacterStringWithoutReturningcallsJsonValueCallTest::testDeriveScalarAnswersTheReturningTypecallsJsonValueCallTest::testRenderWritesTheResponsescallsNestedColumnsTest::testDeriveColumnsFlattensTheNestedColumnsAsNullablecallsNestedColumnsTest::testRenderWritesTheNestedColumnscallsPathColumnTest::testDeriveColumnsAnswersTheDeclaredTypecallsPathColumnTest::testRenderKeepsTheOrderOfTheResponsescallsKeywordCallTest::testDeriveScalarTypesTheFunctioncallsPositionTest::testDeriveScalarAnswersAnIntegercallsPositionTest::testRenderWritesIncallsGetFormatTest::testDeriveScalarAnswersAStringcallsGetFormatTest::testRenderWritesTheKindcallsTrimTest::testDeriveScalarAnswersAStringcallsTrimTest::testRenderWritesEachFormcallsWeightStringParametersTest::testDeriveScalarAnswersABinaryStringcallsWeightStringTest::testDeriveScalarAnswersABinaryStringcallsFullTextSearchTest::testDeriveScalarIsADoubleRelevancecallsFullTextSearchTest::testRenderWritesTheColumnsInParenthesesAndTheModecallsOdbcEscapeTest::testDeriveScalarReadsATemporalLiteralForTheTemporalKindscallsOdbcEscapeTest::testRenderWritesTheBracescallsCaseExpressionTest::testDeriveScalarReportsAValueOfAnotherWidthThanTheOperandcallsCaseExpressionTest::testRenderWritesTheSimpleFormcallsCastTest::testDeriveScalarHasTheTargetTypeAndADateCanBeNullcallsCharsetConversionTest::testDeriveScalarIsAStringOfTheCharacterSetcallsCharsetConversionTest::testRenderWritesUsingcallsCharsetConversionTest::testTheDefaultCharacterSetIsRejectedcallsCollatedTest::testABinaryCastOperandIsRejectedcallsCollatedTest::testDeriveScalarHasTheTypeOfTheOperandcallsCollatedTest::testRenderChainsCollationsFromTheLeftcallsConcatenationTest::testDeriveScalarIsABinaryStringWhenAnOperandIscallsIntervalTest::testRenderWritesTheQuantityAndTheUnitcallsUnaryTest::testDeriveScalarTypesEachOperatorcallsInListTest::testRenderWritesTheNegatedListcallsLikeTest::testAnArithmeticPatternIsRejectedcallsLikeTest::testDeriveScalarIsNullWhenTheEscapeCanBecallsLikeTest::testRenderWritesTheEscapeClausecallsMemberOfTest::testDeriveScalarRejectsTheTestBeforeMySql80callsMemberOfTest::testRenderWritesOfAndTheArrayInParenthesescallsRegexpTest::testAPredicatePatternIsRejectedcallsRegexpTest::testDeriveScalarIsNullWhenThePatternCanBecallsRegexpTest::testRenderWritesTheKeywordcallsSoundsLikeTest::testAPredicateOperandIsRejectedcallsSoundsLikeTest::testDeriveScalarIsAnIntegerTruthValuecallsSoundsLikeTest::testRenderWritesBothWordscallsEscapeRuleTest::testUnderFollowsTheProfileOfAnAnalysiscallsSelectTest::testAStringLiteralUnderAnotherEscapeRuleIsRejectedcallsJsonTableTest::testATableWithoutColumnsIsRejectedcalls
Relations§
Instantiated in 3
- new SqlSemantics\Platform\MySql\Lowering\Leaf\LiteralRule::string() packages/sql-semantics-mysql/src/Lowering/Leaf/LiteralRule.php:196
- new SqlSemantics\Platform\MySql\Lowering\Leaf\LiteralRule::string() packages/sql-semantics-mysql/src/Lowering/Leaf/LiteralRule.php:197
- new SqlSemantics\Platform\MySql\Lowering\Leaf\LiteralRule::string() packages/sql-semantics-mysql/src/Lowering/Leaf/LiteralRule.php:198
Type checks 3
- instanceof SqlSemantics\Platform\MySql\Rules\Query\ItemNaming::own() packages/sql-semantics-mysql/src/Rules/Query/ItemNaming.php:139
- instanceof SqlSemantics\Platform\MySql\Rules\Query\ItemNaming::constant() packages/sql-semantics-mysql/src/Rules/Query/ItemNaming.php:156
- instanceof SqlSemantics\Platform\MySql\Statement\Expression\Access\OdbcEscape::deriveScalar() packages/sql-semantics-mysql/src/Statement/Expression/Access/OdbcEscape.php:63
Type declarations 5
- type SqlSemantics\Platform\MySql\Lowering\Leaf\LiteralRule packages/sql-semantics-mysql/src/Lowering/Leaf/LiteralRule.php:186
- type SqlSemantics\Platform\MySql\Statement\Call\Json\JsonValueCall packages/sql-semantics-mysql/src/Statement/Call/Json/JsonValueCall.php:51
- type SqlSemantics\Platform\MySql\Statement\Call\Json\NestedColumns packages/sql-semantics-mysql/src/Statement/Call/Json/NestedColumns.php:45
- type SqlSemantics\Platform\MySql\Statement\Call\Json\PathColumn packages/sql-semantics-mysql/src/Statement/Call/Json/PathColumn.php:58
- type SqlSemantics\Platform\MySql\Statement\Relation\JsonTable packages/sql-semantics-mysql/src/Statement/Relation/JsonTable.php:56