|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Query\Conditions; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Db\Expression\ExpressionBuilderInterface; |
|
8
|
|
|
use Yiisoft\Db\Expression\ExpressionBuilderTrait; |
|
9
|
|
|
use Yiisoft\Db\Expression\ExpressionInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class NotConditionBuilder builds objects of {@see SimpleCondition}. |
|
13
|
|
|
*/ |
|
14
|
|
|
class SimpleConditionBuilder implements ExpressionBuilderInterface |
|
15
|
|
|
{ |
|
16
|
|
|
use ExpressionBuilderTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Method builds the raw SQL from the $expression that will not be additionally escaped or quoted. |
|
20
|
|
|
* |
|
21
|
|
|
* @param ExpressionInterface|SimpleCondition $expression the expression to be built. |
|
22
|
|
|
* @param array $params the binding parameters. |
|
23
|
|
|
* |
|
24
|
|
|
* @return string the raw SQL that will not be additionally escaped or quoted. |
|
25
|
|
|
*/ |
|
26
|
105 |
|
public function build(ExpressionInterface $expression, array &$params = []): string |
|
27
|
|
|
{ |
|
28
|
105 |
|
$operator = $expression->getOperator(); |
|
|
|
|
|
|
29
|
105 |
|
$column = $expression->getColumn(); |
|
|
|
|
|
|
30
|
105 |
|
$value = $expression->getValue(); |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
105 |
|
if ($column instanceof ExpressionInterface) { |
|
33
|
9 |
|
$column = $this->queryBuilder->buildExpression($column, $params); |
|
34
|
96 |
|
} elseif (is_string($column) && strpos($column, '(') === false) { |
|
35
|
96 |
|
$column = $this->queryBuilder->getDb()->quoteColumnName($column); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
105 |
|
if ($value === null) { |
|
39
|
|
|
return "$column $operator NULL"; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
105 |
|
if ($value instanceof ExpressionInterface) { |
|
43
|
56 |
|
return "$column $operator {$this->queryBuilder->buildExpression($value, $params)}"; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
49 |
|
$phName = $this->queryBuilder->bindParam($value, $params); |
|
47
|
|
|
|
|
48
|
49 |
|
return "$column $operator $phName"; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|