Final Class Yiisoft\Db\Expression\Function\Builder\GreatestBuilder
| Inheritance | Yiisoft\Db\Expression\Function\Builder\GreatestBuilder » Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder |
|---|---|
| Implements | Yiisoft\Db\Expression\ExpressionBuilderInterface |
Builds SQL GREATEST() function expressions for {@see Greatest} objects.
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $queryBuilder | Yiisoft\Db\QueryBuilder\QueryBuilderInterface | Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder | |
| build() | Builds a SQL multi-operand function expression from the given {@see MultiOperandFunction} instance. | Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| buildFromExpression() | Builds a SQL GREATEST() function expression from the given {@see Greatest} object. |
Yiisoft\Db\Expression\Function\Builder\GreatestBuilder |
| buildOperand() | Builds an operand expression of the multi-operand function. | Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder |
Method Details
| public mixed __construct ( Yiisoft\Db\QueryBuilder\QueryBuilderInterface $queryBuilder ) | ||
| $queryBuilder | Yiisoft\Db\QueryBuilder\QueryBuilderInterface | |
public function __construct(protected readonly QueryBuilderInterface $queryBuilder) {}
Defined in: Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder::build()
Builds a SQL multi-operand function expression from the given {@see MultiOperandFunction} instance.
| public string build ( Yiisoft\Db\Expression\Function\MultiOperandFunction $expression, array &$params = [] ) | ||
| $expression | Yiisoft\Db\Expression\Function\MultiOperandFunction |
The expression to build. |
| $params | array |
The parameters to be bound to the query. |
| return | string |
SQL multi-operand function expression. |
|---|---|---|
public function build(ExpressionInterface $expression, array &$params = []): string
{
$operands = $expression->getOperands();
if (empty($operands)) {
throw new InvalidArgumentException(
'The ' . $expression::class . ' expression must have at least one operand.',
);
}
if (count($operands) === 1) {
return '(' . $this->buildOperand($operands[0], $params) . ')';
}
return $this->buildFromExpression($expression, $params);
}
Builds a SQL GREATEST() function expression from the given {@see Greatest} object.
| 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 |
|---|---|---|
protected function buildFromExpression(MultiOperandFunction $expression, array &$params): string
{
$builtOperands = [];
foreach ($expression->getOperands() as $operand) {
$builtOperands[] = $this->buildOperand($operand, $params);
}
return 'GREATEST(' . implode(', ', $builtOperands) . ')';
}
Defined in: Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder::buildOperand()
Builds an operand expression of the multi-operand function.
| protected string buildOperand ( mixed $operand, array &$params ) | ||
| $operand | mixed | |
| $params | array | |
protected function buildOperand(mixed $operand, array &$params): string
{
if (is_string($operand)) {
return $this->queryBuilder->getQuoter()->quoteColumnName($operand);
}
return $this->queryBuilder->buildValue($operand, $params);
}
Signup or Login in order to comment.