Branch
+ Inheritance diagram for Branch:

Description

A CASE expression, with or without a subject expression.

If a subject is used, WHEN relies on equating the subject's evaluation to a literal value. This is also known as a "simple case", and is not null-safe. If you are choosing between known states, this may be the use-case for you.

Otherwise WHEN relies on arbitrary predication. This is also known as a "searched case", and may be constructed in a null-safe manner. If you are choosing amongst complex states, this may be the use-case for you.

With a subject (simple case):

CASE subject
WHEN value THEN value
...
END

Without a subject (searched case):

CASE
WHEN predicate THEN value
...
END

Protected Properties

string $else
 
string $subject
 
string[] $values = []
 [when => then] More...
 
- Protected Properties inherited from Expression
DB $db
 
string $expression
 

Public Static Methods

magic static self factory (DB $db, string $subject=null, array $values=[])
 
- Public Static Methods inherited from Expression
magic static self factory (DB $db, string $expression)
 

Public Methods

 __construct (DB $db, string $subject=null, array $values=[])
 
string __toString ()
 
$this else ($else)
 
$this when ($expression, $then)
 Quotes and sets a conditional value. More...
 
$this whenValues (array $values)
 Quotes and sets multiple conditional values for the subject. More...
 
- Public Methods inherited from Expression
 __construct (DB $db, string $expression)
 
- Public Methods inherited from ValueTrait
Value coalesce (array $values)
 COALESCE($this, ...$values) More...
 
- Public Methods inherited from AggregateTrait
Num avg ()
 AVG($this) More...
 
Num avgDistinct ()
 AVG(DISTINCT $this) More...
 
Num count ()
 COUNT($this) More...
 
Num countDistinct ()
 COUNT(DISTINCT $this) More...
 
Str groupConcat (string $delimiter=',')
 GROUP_CONCAT($this) using a delimiter. More...
 
Num max ()
 MAX($this) More...
 
Num min ()
 MIN($this) More...
 
Num sum ()
 SUM($this) More...
 
Num sumDistinct ()
 SUM(DISTINCT $this) More...
 
- Public Methods inherited from ComparisonTrait
Predicate is ($arg)
 Null-safe type-strict equality. More...
 
Predicate isBetween ($min, $max)
 $this BETWEEN $min AND $max (inclusive) More...
 
Predicate isEqual ($arg)
 See Predicate::match(). More...
 
Predicate isFalse ()
 $this IS FALSE More...
 
Predicate isGt ($arg)
 $this > $arg, or driver-appropriate $this > ALL (SELECT ...) More...
 
Predicate isGtAny (Select $select)
 Driver-appropriate $this > ANY (SELECT ...) More...
 
Predicate isGte ($arg)
 $this >= $arg, or driver-appropriate $this >= ALL (SELECT ...) More...
 
Predicate isGteAny (Select $select)
 Driver-appropriate $this >= ANY (SELECT ...) More...
 
Predicate isLike (string $pattern)
 $this LIKE $pattern More...
 
Predicate isLt ($arg)
 $this < $arg, or driver-appropriate $this < ALL (SELECT ...) More...
 
Predicate isLtAny (Select $select)
 Driver-appropriate $this < ANY (SELECT ...) More...
 
Predicate isLte ($arg)
 $this <= $arg, or driver-appropriate $this <= ALL (SELECT ...) More...
 
Predicate isLteAny (Select $select)
 Driver-appropriate $this <= ANY (SELECT ...) More...
 
Predicate isNot ($arg)
 Null-safe type-strict inequality. More...
 
Predicate isNotBetween ($min, $max)
 $this NOT BETWEEN $min AND $max (inclusive) More...
 
Predicate isNotEqual ($arg)
 $this <> $arg or $this NOT IN ($arg) More...
 
Predicate isNotLike (string $pattern)
 $this NOT LIKE $pattern More...
 
Predicate isNotNull ()
 $this IS NOT NULL More...
 
Predicate isNotRegExp (string $pattern)
 $this NOT REGEXP $pattern More...
 
Predicate isNull ()
 $this IS NULL More...
 
Predicate isRegExp (string $pattern)
 $this REGEXP $pattern More...
 
Branch switch (array $values=[])
 CASE $this ... More...
 
- Public Methods inherited from DateTimeCastTrait
DateTime toDateTime ()
 Interpret the expression as a datetime. More...
 
- Public Methods inherited from NumCastFloatTrait
Num toFloat ()
 Casts the expression as a floating point number. More...
 
- Public Methods inherited from NumCastIntTrait
Num toInt ()
 Casts the expression as a signed integer. More...
 
- Public Methods inherited from StrCastTrait
Str toStr ()
 Casts the expression as a character string. More...
 

Properties

◆ $values

string [] $values = []
protected

[when => then]

Constructor

◆ __construct()

__construct ( DB  $db,
string  $subject = null,
array  $values = [] 
)
Parameters
DB$db
null | string$subject
array$values[when => then] for the subject.

Methods

◆ __toString()

string __toString ( )
Returns
string

Reimplemented from Expression.

◆ else()

$this else (   $else)
Parameters
string | ValueInterface$else
Returns
$this

◆ factory()

magic static self factory ( DB  $db,
string  $subject = null,
array  $values = [] 
)
static
Returns
self

◆ when()

$this when (   $expression,
  $then 
)

Quotes and sets a conditional value.

Parameters
string | ValueInterface$expression
string | ValueInterface$then
Returns
$this

◆ whenValues()

$this whenValues ( array  $values)

Quotes and sets multiple conditional values for the subject.

Keys are quoted as literal values.

Use when() if you need an expression for the WHEN clause.

Parameters
array$values[when => then]
Returns
$this