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\mssql\conditions; |
9
|
|
|
|
10
|
|
|
use yii\base\NotSupportedException; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
* |
15
|
|
|
* @author Dmytro Naumenko <[email protected]> |
16
|
|
|
* @since 2.0.14 |
17
|
|
|
*/ |
18
|
|
|
class InConditionBuilder extends \yii\db\conditions\InConditionBuilder |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
* @throws NotSupportedException if `$columns` is an array |
23
|
|
|
*/ |
24
|
|
|
protected function buildSubqueryInCondition($operator, $columns, $values, &$params) |
25
|
|
|
{ |
26
|
|
|
if (is_array($columns)) { |
27
|
|
|
throw new NotSupportedException(__METHOD__ . ' is not supported by MSSQL.'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return parent::buildSubqueryInCondition($operator, $columns, $values, $params); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
protected function buildCompositeInCondition($operator, $columns, $values, &$params) |
37
|
|
|
{ |
38
|
|
|
$quotedColumns = []; |
39
|
|
|
foreach ($columns as $i => $column) { |
40
|
|
|
$quotedColumns[$i] = strpos($column, '(') === false ? $this->queryBuilder->db->quoteColumnName($column) : $column; |
41
|
|
|
} |
42
|
|
|
$vss = []; |
43
|
|
|
foreach ($values as $value) { |
44
|
|
|
$vs = []; |
45
|
|
|
foreach ($columns as $i => $column) { |
46
|
|
|
if (isset($value[$column])) { |
47
|
|
|
$phName = $this->queryBuilder->bindParam($value[$column], $params); |
48
|
|
|
$vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' = ' : ' != ') . $phName; |
49
|
|
|
} else { |
50
|
|
|
$vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' IS' : ' IS NOT') . ' NULL'; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
$vss[] = '(' . implode($operator === 'IN' ? ' AND ' : ' OR ', $vs) . ')'; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return '(' . implode($operator === 'IN' ? ' OR ' : ' AND ', $vss) . ')'; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|