0 follower

Class Yiisoft\Db\QueryBuilder\Condition\Builder\BetweenBuilder

InheritanceYiisoft\Db\QueryBuilder\Condition\Builder\BetweenBuilder
ImplementsYiisoft\Db\Expression\ExpressionBuilderInterface

Build an object of {@see Between} or {@see NotBetween} into SQL expressions.

Protected Methods

Hide inherited methods

Method Description Defined By
createPlaceholder() Attaches $value to $params array and return placeholder. Yiisoft\Db\QueryBuilder\Condition\Builder\BetweenBuilder

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\Db\QueryBuilder\QueryBuilderInterface $queryBuilder )
$queryBuilder Yiisoft\Db\QueryBuilder\QueryBuilderInterface

                public function __construct(private readonly QueryBuilderInterface $queryBuilder) {}

            
build() public method

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";
}

            
createPlaceholder() protected method

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);
}