Final Class Yiisoft\Db\Mssql\Builder\ShortestBuilder
| Inheritance | Yiisoft\Db\Mssql\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 TOP 1 value FROM (
SELECT operand1 AS value
UNION
SELECT operand2 AS value
) AS t ORDER BY LEN(value) ASC)
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| buildFromExpression() | Builds a SQL expression to represent the function which returns the shortest string. | Yiisoft\Db\Mssql\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 "(SELECT TOP 1 value FROM ($unions) AS t ORDER BY LEN(value) ASC)";
}
Signup or Login in order to comment.