classSearchedCase
final class SearchedCase
implements ProgramStatement
uses Snapshot
Public API: explicitly declared with
@visibility public.The searched CASE statement: the statements of the first WHEN whose search condition is true run.
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 WHEN a > 1 THEN SELECT 1; WHEN a < 0 THEN SELECT 2; END CASE');
[count($create->statement->body->branches), $create->statement->body->otherwise] // => [2, []]Properties§
public non-empty-list<ConditionalBranch> $branchespublic list<ProgramStatement|Statement> $otherwiseMethods§
public function __construct(
list<ConditionalBranch> $branches,
list<ProgramStatement|Statement> $otherwise = [],
)Parameters
$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 50
- class-const ConditionalBranch::class() line 50
- method-call StatementSequence::members() line 51
- new StatementSequence line 51
public function deriveProgram(Derivation $derivation, ProgramScope $scope): voidDerives the conditions and the statements of every branch.
Parameters
$derivation | Derivation | |
$scope | ProgramScope |
Calls 2
- method-call FlowFacts::branches() line 59
- new FlowFacts line 59
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 67
- method-call StatementSequence::write() line 73
- new StatementSequence line 73
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::testChoiceLowersASearchedCasecallsStatementRuleTest::providerEventLowersTheStatementOfAnEventcallsReturnSearchTest::providerFoundFindsANestedReturncallsReturnSearchTest::testNestedAnswersTheElseStatementsBeforeTheBranchStatementscallsProgramStatementTest::providerDeriveProgramIsImplementedByTheProgramStatementClassescalls