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

A CASE expression in its simple form, CASE operand WHEN value THEN result … [ELSE result] END, or its searched form, CASE WHEN condition THEN result … [ELSE result] END (Item_func_case).

The branches are tried in order and the first that matches gives the result; the order is kept as written.

Rule: MYSQL-CASE-001. Facts: the type is the aggregate of the results (MYSQL-TYPE-AGGREGATION-001); the value is NULL when a result can be NULL or when there is no ELSE. In the simple form the operand and every value must have the same number of columns (MYSQL-OPERAND-COLUMNS-001); conditions and results take single values. Terminates: the parts are strict parts. Source: https://dev.mysql.com/doc/refman/8.4/en/flow-control-functions.html#operator_case. Status: Implemented.

Typing a CASE by its resultsdoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze("SELECT a FROM t WHERE CASE a WHEN 1 THEN 'x' ELSE 'y' END");
    [$query->facts->scalar($query->statement->where)->type->descriptor->name(), $query->facts->scalar($query->statement->where)->nullability] // => ['VARCHAR', \SqlSemantics\Platform\MySql\Model\Statement\Type\Nullability::NotNull]

Properties§

public non-empty-list<CaseBranch> $branches
public Scalar|null $operand
public Scalar|null $else = null

Methods§

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

Parameters

$operandScalar|nullThe compared value of the simple form; null for the searched form
$brancheslist<CaseBranch>The branches in order; at least one
$elseScalar|nullThe result after ELSE, when written
Calls 2
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the operand, every branch and the ELSE result, and aggregates the result types.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

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

Writes CASE, the operand, the branches, the ELSE result and END.

Parameters

$outOutput
Test cases 1
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 4
Other tests reaching this symbol 1

Relations§

Instantiated in 1