1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.yiiframework.com/ |
4
|
|
|
* @copyright Copyright (c) 2008 Yii Software LLC |
5
|
|
|
* @license http://www.yiiframework.com/license/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace yii\db\sqlite\conditions; |
9
|
|
|
|
10
|
|
|
use yii\base\NotSupportedException; |
11
|
|
|
use yii\db\ExpressionInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* {@inheritdoc} |
15
|
|
|
* |
16
|
|
|
* @author Dmytro Naumenko <[email protected]> |
17
|
|
|
* @since 2.0.14 |
18
|
|
|
*/ |
19
|
|
|
class InConditionBuilder extends \yii\db\conditions\InConditionBuilder |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
* @throws NotSupportedException if `$columns` is an array |
24
|
|
|
*/ |
25
|
|
|
protected function buildSubqueryInCondition($operator, $columns, $values, &$params) |
26
|
|
|
{ |
27
|
|
|
if (is_array($columns)) { |
28
|
|
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return parent::buildSubqueryInCondition($operator, $columns, $values, $params); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
protected function buildCompositeInCondition($operator, $columns, $values, &$params) |
38
|
|
|
{ |
39
|
|
|
$quotedColumns = []; |
40
|
|
|
foreach ($columns as $i => $column) { |
41
|
|
|
if ($column instanceof ExpressionInterface) { |
42
|
|
|
$column = $column->expression; |
|
|
|
|
43
|
|
|
} |
44
|
|
|
$quotedColumns[$i] = strpos($column, '(') === false ? $this->queryBuilder->db->quoteColumnName($column) : $column; |
45
|
|
|
} |
46
|
|
|
$vss = []; |
47
|
|
|
foreach ($values as $value) { |
48
|
|
|
$vs = []; |
49
|
|
|
foreach ($columns as $i => $column) { |
50
|
|
|
if ($column instanceof ExpressionInterface) { |
51
|
|
|
$column = $column->expression; |
52
|
|
|
} |
53
|
|
|
if (isset($value[$column])) { |
54
|
|
|
$phName = $this->queryBuilder->bindParam($value[$column], $params); |
55
|
|
|
$vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' = ' : ' != ') . $phName; |
56
|
|
|
} else { |
57
|
|
|
$vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' IS' : ' IS NOT') . ' NULL'; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
$vss[] = '(' . implode($operator === 'IN' ? ' AND ' : ' OR ', $vs) . ')'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return '(' . implode($operator === 'IN' ? ' OR ' : ' AND ', $vss) . ')'; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|