final class WeightString
    implements Scalar
    uses Snapshot
Public API: explicitly declared with @visibility public.

A call of WEIGHT_STRING(): the binary weight string of a string under its collation.

Rule: MYSQL-WEIGHT-STRING-001. The argument may be cast to CHAR(n) or BINARY(n) first; MySQL 5.6 and 5.7 also take a LEVEL clause of levels or a range of levels, and not after a BINARY cast. The result is a binary string; it is NULL when the argument is NULL. Terminates: the operand is a strict part. Source: https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_weight-string, https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_weight-string. Status: Implemented.

Typing WEIGHT_STRING()doctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze("SELECT WEIGHT_STRING('ab' AS CHAR(4))");
    $query->field(0)->type->descriptor->name() // => 'VARBINARY'
Refusing levels after a binary castdoctest
new \SqlSemantics\Platform\MySql\Statement\Call\Weight\WeightString(new \SqlSemantics\Platform\MySql\Statement\Literal\NullLiteral(), \SqlSemantics\Platform\MySql\Statement\Call\Weight\WeightCast::Binary, new \SqlSemantics\Platform\MySql\Statement\Literal\Numeral('4'), [new \SqlSemantics\Platform\MySql\Statement\Call\Weight\WeightLevel(new \SqlSemantics\Platform\MySql\Statement\Literal\Numeral('1'))]) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\InvalidConstruction

Properties§

public list<WeightLevel> $levels
public Scalar $subject
public WeightCast|null $cast = null
public Numeral|null $length = null
public WeightLevelRange|null $range = null

Methods§

public function __construct(
    public Scalar $subject,
    public WeightCast|null $cast = null,
    public Numeral|null $length = null,
    list<WeightLevel> $levels = [],
    public WeightLevelRange|null $range = null,
)

Parameters

$subjectScalarThe string
$castWeightCast|nullThe type the string is cast to
$lengthNumeral|nullThe length of the cast; present exactly with a cast
$levelslist<WeightLevel>The levels of the LEVEL clause
$rangeWeightLevelRange|nullThe range of the LEVEL clause
Calls 4
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the operand; the result is a binary string.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

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

Writes the call.

Parameters

$outOutput
Test cases 1
Calls 2

Test cases 4§

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

Dedicated tests 2
Other tests reaching this symbol 2

Relations§

Instantiated in 3