0 follower

Final Class Yiisoft\Db\Mysql\Builder\LongestBuilder

InheritanceYiisoft\Db\Mysql\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 operand1 AS value
UNION SELECT operand2 AS value
ORDER BY LENGTH(value) DESC LIMIT 1)

Protected Methods

Hide inherited methods

Method Description Defined By
buildFromExpression() Builds a SQL expression to represent the function which returns the longest string. Yiisoft\Db\Mysql\Builder\LongestBuilder

Method Details

Hide inherited methods

buildFromExpression() protected method

Builds a SQL expression to represent the function which returns the longest string.

protected string buildFromExpression ( \Yiisoft\Db\Expression\Function\Longest $expression, array &$params )
$expression \Yiisoft\Db\Expression\Function\Longest

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) DESC LIMIT 1)";
}