1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
namespace yii\db\oci\conditions;
use yii\db\conditions\InCondition;
use yii\db\ExpressionInterface;
/**
* {@inheritdoc}
*/
class InConditionBuilder extends \yii\db\conditions\InConditionBuilder
{
/**
* Method builds the raw SQL from the $expression that will not be additionally
* escaped or quoted.
*
* @param ExpressionInterface|InCondition $expression the expression to be built.
* @param array $params the binding parameters.
* @return string the raw SQL that will not be additionally escaped or quoted.
*/
public function build(ExpressionInterface $expression, array &$params = [])
{
$splitCondition = $this->splitCondition($expression, $params);
if ($splitCondition !== null) {
return $splitCondition;
}
return parent::build($expression, $params);
}
/**
* Oracle DBMS does not support more than 1000 parameters in `IN` condition.
* This method splits long `IN` condition into series of smaller ones.
*
* @param ExpressionInterface|InCondition $condition the expression to be built.
* @param array $params the binding parameters.
* @return string|null null when split is not required. Otherwise - built SQL condition.
*/
protected function splitCondition(InCondition $condition, &$params)
{
$operator = $condition->getOperator();
$values = $condition->getValues();
$column = $condition->getColumn();
if ($values instanceof \Traversable) {
$values = iterator_to_array($values);
}
if (!is_array($values)) {
return null;
}
$maxParameters = 1000;
$count = count($values);
if ($count <= $maxParameters) {
return null;
}
$slices = [];
for ($i = 0; $i < $count; $i += $maxParameters) {
$slices[] = $this->queryBuilder->createConditionFromArray([$operator, $column, array_slice($values, $i, $maxParameters)]);
}
array_unshift($slices, ($operator === 'IN') ? 'OR' : 'AND');
return $this->queryBuilder->buildCondition($slices, $params);
}
}