Class Yiisoft\Db\QueryBuilder\Condition\Builder\BetweenBuilder
| Inheritance | Yiisoft\Db\QueryBuilder\Condition\Builder\BetweenBuilder |
|---|---|
| Implements | Yiisoft\Db\Expression\ExpressionBuilderInterface |
Build an object of {@see Between} or {@see NotBetween} into SQL expressions.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Db\QueryBuilder\Condition\Builder\BetweenBuilder | |
| build() | Build SQL for {@see Between} or {@see NotBetween}. | Yiisoft\Db\QueryBuilder\Condition\Builder\BetweenBuilder |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| createPlaceholder() | Attaches $value to $params array and return placeholder. |
Yiisoft\Db\QueryBuilder\Condition\Builder\BetweenBuilder |
Method Details
| public mixed __construct ( Yiisoft\Db\QueryBuilder\QueryBuilderInterface $queryBuilder ) | ||
| $queryBuilder | Yiisoft\Db\QueryBuilder\QueryBuilderInterface | |
public function __construct(private readonly QueryBuilderInterface $queryBuilder) {}
Build SQL for {@see Between} or {@see NotBetween}.
| public string build ( Yiisoft\Db\QueryBuilder\Condition\Between|Yiisoft\Db\QueryBuilder\Condition\NotBetween $expression, array &$params = [] ) | ||
| $expression | Yiisoft\Db\QueryBuilder\Condition\Between|Yiisoft\Db\QueryBuilder\Condition\NotBetween | |
| $params | array | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
|---|---|---|
public function build(ExpressionInterface $expression, array &$params = []): string
{
$operator = match ($expression::class) {
Between::class => 'BETWEEN',
NotBetween::class => 'NOT BETWEEN',
};
$column = $expression->column instanceof ExpressionInterface
? $this->queryBuilder->buildExpression($expression->column, $params)
: $this->queryBuilder->getQuoter()->quoteColumnName($expression->column);
$phName1 = $this->createPlaceholder($expression->intervalStart, $params);
$phName2 = $this->createPlaceholder($expression->intervalEnd, $params);
return "$column $operator $phName1 AND $phName2";
}
Attaches $value to $params array and return placeholder.
| protected string createPlaceholder ( mixed $value, array &$params ) | ||
| $value | mixed | |
| $params | array | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
|---|---|---|
protected function createPlaceholder(mixed $value, array &$params): string
{
if ($value instanceof ExpressionInterface) {
return $this->queryBuilder->buildExpression($value, $params);
}
return $this->queryBuilder->bindParam($value, $params);
}
Signup or Login in order to comment.