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

A conversion of a value to the storage class the affinity of a type name selects.

Rule: SQLITE-CAST-001. The affinity of the type name decides the result: INTEGER, TEXT, BLOB and REAL affinity give that storage class; NUMERIC affinity, which an absent type name also has, gives INTEGER or REAL. A NULL operand stays NULL, so the NULL fact is that of the operand. Source: https://sqlite.org/lang_expr.html#castexpr. Status: Implemented.

Reading the type of a CASTdoctest
$query = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('SELECT CAST(a AS VARCHAR(10)) FROM t');
    [$query->statement->columns[0]->expression->target->text(), $query->field(0)->type->descriptor] // => ['VARCHAR', \SqlSemantics\Platform\Sqlite\Statement\Type\Storage::Text]

Properties§

public Scalar $operand
public TypeName|null $target = null

Methods§

public function __construct(public Scalar $operand, public TypeName|null $target = null)

Parameters

$operandScalarThe converted expression
$targetTypeName|nullThe type name; null when none is written
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the storage class from the affinity of the type name.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

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

Writes the conversion.

Parameters

$outOutput
Calls 1

Test cases 16§

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

Dedicated tests 1
Other tests reaching this symbol 15

Relations§

Instantiated in 1
Type checks 4