final class SimpleCase
    implements ProgramStatement
    uses Snapshot
Public API: explicitly declared with @visibility public.

The simple CASE statement: an operand compared for equality with the value of each WHEN.

It differs from the CASE expression: it runs statements, ends with END CASE and fails when no branch matches and there is no ELSE. The facts follow MYSQL-PROGRAM-FLOW-001. Source: https://dev.mysql.com/doc/refman/8.4/en/case.html.

Reading a simple CASE statementdoctest
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE PROCEDURE p(a INT) CASE a WHEN 1 THEN SELECT 1; ELSE SELECT 2; END CASE');
    [count($create->statement->body->branches), count($create->statement->body->otherwise)] // => [1, 1]

Properties§

public non-empty-list<ConditionalBranch> $branches
public list<ProgramStatement|Statement> $otherwise
public Scalar $operand

Methods§

public function __construct(
    public Scalar $operand,
    list<ConditionalBranch> $branches,
    list<ProgramStatement|Statement> $otherwise = [],
)

Parameters

$operandScalarThe value every WHEN value is compared with
$brancheslist<ConditionalBranch>The WHEN branches; at least one
$otherwiselist<ProgramStatement|Statement>The statements of ELSE; empty without ELSE

Throws

InvalidConstruction When there is no branch or a member is of another class
Calls 4
public function deriveProgram(Derivation $derivation, ProgramScope $scope): void

Derives the operand, the compared values and the statements of every branch.

Parameters

$derivationDerivation
$scopeProgramScope
Calls 3
public function render(Output $out): void

Writes the statement.

Parameters

$outOutput
Calls 3

Test cases 7§

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 5

Relations§

Instantiated in 1
Type checks 1
Type declarations 1