Abstract Class Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder
Base class for building SQL representation of multi-operand function expressions.
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 multi-operand function expression from the given {@see MultiOperandFunction} instance. | Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder |
| buildOperand() | Builds an operand expression of the multi-operand function. | Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder |
Property Details
Method Details
| public mixed __construct ( Yiisoft\Db\QueryBuilder\QueryBuilderInterface $queryBuilder ) | ||
| $queryBuilder | Yiisoft\Db\QueryBuilder\QueryBuilderInterface | |
public function __construct(protected readonly QueryBuilderInterface $queryBuilder) {}
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 multi-operand function expression from the given {@see MultiOperandFunction} instance.
| protected abstract string buildFromExpression ( Yiisoft\Db\Expression\Function\MultiOperandFunction $expression, array &$params ) | ||
| $expression | Yiisoft\Db\Expression\Function\MultiOperandFunction |
The expression to build from. |
| $params | array |
The parameters to be bound to the query. |
| return | string |
SQL multi-operand function expression. |
|---|---|---|
abstract protected function buildFromExpression(MultiOperandFunction $expression, array &$params): string;
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.