Final Class Yiisoft\Db\Mssql\Builder\LongestBuilder
| Inheritance | Yiisoft\Db\Mssql\Builder\LongestBuilder » Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder |
|---|
Builds SQL representation of function expressions which returns the longest string from a set of operands.
(SELECT TOP 1 value FROM (
SELECT operand1 AS value
UNION
SELECT operand2 AS value
) AS t ORDER BY LEN(value) DESC)
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| buildFromExpression() | Builds a SQL expression to represent the function which returns the longest string. | Yiisoft\Db\Mssql\Builder\LongestBuilder |
Method Details
Builds a SQL expression to represent the function which returns the longest string.
| protected string buildFromExpression ( \Yiisoft\Db\Expression\Function\Greatest $expression, array &$params ) | ||
| $expression | \Yiisoft\Db\Expression\Function\Greatest |
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 "(SELECT TOP 1 value FROM ($unions) AS t ORDER BY LEN(value) DESC)";
}
Signup or Login in order to comment.