switch complex expr

This commit is contained in:
Yuri Kuznetsov
2023-03-07 18:52:49 +02:00
parent 2d62c902cb
commit 369f3ba9a5
4 changed files with 66 additions and 0 deletions
@@ -950,6 +950,28 @@ abstract class BaseQueryComposer implements QueryComposer
}
switch ($function) {
case 'SWITCH':
if (count($argumentPartList) < 2) {
throw new RuntimeException("Not enough arguments for SWITCH function.");
}
$part = "CASE";
for ($i = 0; $i < floor(count($argumentPartList) / 2); $i++) {
$whenPart = $argumentPartList[$i * 2];
$thenPart = $argumentPartList[$i * 2 + 1];
$part .= " WHEN {$whenPart} THEN {$thenPart}";
}
if (count($argumentPartList) % 2) {
$part .= " ELSE " . end($argumentPartList);
}
$part .= " END";
return $part;
case 'MONTH':
return "DATE_FORMAT({$part}, '%Y-%m')";