final class StringLiteral
    implements Scalar
    uses Snapshot
Public API: explicitly declared with @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.

Reading the value of adjacent stringsdoctest
$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> $segments
public EscapeRule $escapes = EscapeRule::Backslash
public Name|null $introducer = null
public bool $national = false

Methods§

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

$segmentsarray<array-key, string|int|bool|object|null>The decoded bytes of each adjacent quoted string, as a list of strings; at least one
$escapesEscapeRuleThe rule the value is spelled under; the rule of the language profile
$introducerName|nullThe introduced character set, in lower case
$nationalboolWhether the literal is written `N'...'`; excludes an introducer
Calls 6
public function value(): string

Answers the value of the literal: the concatenation of its segments.

Returns

string
Calls 1
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the character string type; a literal is never NULL.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

Calls 9
public function render(Output $out): void

Writes the introducer or the national prefix and each segment in single quotes.

Parameters

$outOutput
Calls 4

Test cases 82§

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

Dedicated tests 12
Other tests reaching this symbol 70

Relations§

Instantiated in 3
Type checks 3
Type declarations 5