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

A CASE expression: the result of the first branch that matches, in written order.

Rule: SQLITE-CASE-001. With a base expression each WHEN value is compared with it and has its width; without one each WHEN is a condition, a single value (SQLITE-ROW-VALUE-USE-001), as every result is. The result is one of the THEN results or the ELSE result, so its type is the choice over their types. Without ELSE the result is NULL when no branch matches; otherwise it can be NULL when a result can. Source: https://sqlite.org/lang_expr.html#the_case_expression. Status: Implemented.

Reading the type of a CASEdoctest
$query = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze("SELECT CASE a WHEN 1 THEN 'x' ELSE 2 END FROM t");
    [count($query->field(0)->type->alternatives), $query->field(0)->nullability] // => [2, \SqlSemantics\Platform\Sqlite\Model\Statement\Type\Nullability::NotNull]
Refusing an expression without branchesdoctest
new \SqlSemantics\Platform\Sqlite\Statement\Expression\CaseExpression(null, []) // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvalidConstruction

Properties§

public non-empty-list<CaseBranch> $branches
public Scalar|null $base
public Scalar|null $otherwise = null

Methods§

public function __construct(
    public Scalar|null $base,
    list<CaseBranch> $branches,
    public Scalar|null $otherwise = null,
)

Parameters

$baseScalar|nullThe expression every WHEN value is compared with
$brancheslist<CaseBranch>The branches in written order; at least one
$otherwiseScalar|nullThe ELSE result
Calls 2
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives every part and the choice over the results.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

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

Writes the expression.

Parameters

$outOutput
Calls 2

Test cases 5§

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 4

Relations§

Instantiated in 1
Type checks 1
Type declarations 2