classSimpleCase
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.
$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> $branchespublic list<ProgramStatement|Statement> $otherwisepublic Scalar $operandMethods§
public function __construct(
public Scalar $operand,
list<ConditionalBranch> $branches,
list<ProgramStatement|Statement> $otherwise = [],
)Parameters
$operand | Scalar | The value every WHEN value is compared with |
$branches | list<ConditionalBranch> | The WHEN branches; at least one |
$otherwise | list<ProgramStatement|Statement> | The statements of ELSE; empty without ELSE |
Throws
InvalidConstruction When there is no branch or a member is of another classCalls 4
- static-call Check::listOf() line 54
- class-const ConditionalBranch::class() line 54
- method-call StatementSequence::members() line 55
- new StatementSequence line 55
public function deriveProgram(Derivation $derivation, ProgramScope $scope): voidDerives the operand, the compared values and the statements of every branch.
Parameters
$derivation | Derivation | |
$scope | ProgramScope |
Calls 3
- method-call Derivation::scalar() line 63
- method-call FlowFacts::branches() line 64
- new FlowFacts line 64
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 72
- method-call StatementSequence::write() line 78
- new StatementSequence line 78
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
FlowRuleTest::testChoiceLowersASimpleCasecallsStatementRuleTest::testStatementRoutesEveryKindOfProgramStatementcallsReturnSearchTest::providerFoundFindsANestedReturncallsReturnSearchTest::testNestedAnswersTheElseStatementsBeforeTheBranchStatementscallsProgramStatementTest::providerDeriveProgramIsImplementedByTheProgramStatementClassescalls