classCaseExpression
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.
$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]new \SqlSemantics\Platform\Sqlite\Statement\Expression\CaseExpression(null, []) // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvalidConstructionProperties§
public non-empty-list<CaseBranch> $branchespublic Scalar|null $basepublic Scalar|null $otherwise = nullMethods§
public function __construct(
public Scalar|null $base,
list<CaseBranch> $branches,
public Scalar|null $otherwise = null,
)Parameters
$base | Scalar|null | The expression every WHEN value is compared with |
$branches | list<CaseBranch> | The branches in written order; at least one |
$otherwise | Scalar|null | The ELSE result |
Calls 2
- static-call Check::listOf() line 52
- class-const CaseBranch::class() line 52
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives every part and the choice over the results.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 9
- new RowValueUse line 60
- method-call Derivation::scalar() line 61
- class-const Nullability::Nullable() line 63
- class-const Nullability::NotNull() line 63
- method-call RowValueUse::single() line 66
- method-call RowValueUse::uniform() line 66
- new ScalarFact line 79
- method-call Storages::either() line 79
- new Storages line 79
public function render(Output $out): voidWrites the expression.
Parameters
$out | Output |
Calls 2
- method-call Output::keyword() line 87
- method-call Output::node() line 89
Test cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.