Final Class Yiisoft\Db\Mysql\Builder\ShortestBuilder
| Inheritance | Yiisoft\Db\Mysql\Builder\ShortestBuilder » Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder |
|---|
Builds SQL representation of function expressions which return the shortest string from a set of operands.
(SELECT operand1 AS value
UNION SELECT operand2 AS value
ORDER BY LENGTH(value) ASC LIMIT 1)
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| buildFromExpression() | Builds a SQL expression to represent the function which returns the shortest string. | Yiisoft\Db\Mysql\Builder\ShortestBuilder |
Method Details
Builds a SQL expression to represent the function which returns the shortest string.
| protected string buildFromExpression ( \Yiisoft\Db\Expression\Function\Shortest $expression, array &$params ) | ||
| $expression | \Yiisoft\Db\Expression\Function\Shortest |
The expression to build. |
| $params | array |
The parameters to bind. |
| return | string |
The SQL expression. |
|---|---|---|
protected function buildFromExpression(MultiOperandFunction $expression, array &$params): string
{
$selects = [];
foreach ($expression->getOperands() as $operand) {
$selects[] = 'SELECT ' . $this->buildOperand($operand, $params) . ' AS value';
}
$unions = implode(' UNION ', $selects);
return "($unions ORDER BY LENGTH(value) ASC LIMIT 1)";
}
Signup or Login in order to comment.