Skip to content

Commit fc0d175

Browse files
authored
Adapt to Yii DB changes in LIKE condition (#434)
1 parent 6c5675f commit fc0d175

3 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/Builder/LikeBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
*/
1212
final class LikeBuilder extends \Yiisoft\Db\QueryBuilder\Condition\Builder\LikeBuilder
1313
{
14-
protected function parseOperator(Like $expression): array
14+
protected function parseOperator(Like $condition): array
1515
{
16-
[$andor, $not, $operator] = parent::parseOperator($expression);
16+
[$not, $operator] = parent::parseOperator($condition);
1717

18-
$operator = match ($expression->caseSensitive) {
18+
$operator = match ($condition->caseSensitive) {
1919
true => 'LIKE',
2020
false => 'ILIKE',
2121
default => $operator,
2222
};
2323

24-
return [$andor, $not, $operator];
24+
return [$not, $operator];
2525
}
2626
}

src/DQLQueryBuilder.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ protected function defaultConditionClasses(): array
3838
...parent::defaultConditionClasses(),
3939
'ILIKE' => Like::class,
4040
'NOT ILIKE' => Like::class,
41-
'OR ILIKE' => Like::class,
42-
'OR NOT ILIKE' => Like::class,
4341
];
4442
}
4543

tests/Provider/QueryBuilderProvider.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Yiisoft\Db\Pgsql\Column\IntegerColumn;
1515
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
1616
use Yiisoft\Db\Query\Query;
17+
use Yiisoft\Db\QueryBuilder\Condition\LikeConjunction;
1718

1819
use function array_replace;
1920
use function version_compare;
@@ -67,14 +68,14 @@ public static function buildCondition(): array
6768
/* empty values */
6869
[['ilike', 'name', []], '0=1', []],
6970
[['not ilike', 'name', []], '', []],
70-
[['or ilike', 'name', []], '0=1', []],
71-
[['or not ilike', 'name', []], '', []],
71+
[['ilike', 'name', [], 'conjunction' => LikeConjunction::Or], '0=1', []],
72+
[['not ilike', 'name', [], 'conjunction' => LikeConjunction::Or], '', []],
7273

7374
/* simple ilike */
7475
[['ilike', 'name', 'heyho'], '"name" ILIKE :qp0', [':qp0' => new Param('%heyho%', DataType::STRING)]],
7576
[['not ilike', 'name', 'heyho'], '"name" NOT ILIKE :qp0', [':qp0' => new Param('%heyho%', DataType::STRING)]],
76-
[['or ilike', 'name', 'heyho'], '"name" ILIKE :qp0', [':qp0' => new Param('%heyho%', DataType::STRING)]],
77-
[['or not ilike', 'name', 'heyho'], '"name" NOT ILIKE :qp0', [':qp0' => new Param('%heyho%', DataType::STRING)]],
77+
[['ilike', 'name', 'heyho', 'conjunction' => LikeConjunction::Or], '"name" ILIKE :qp0', [':qp0' => new Param('%heyho%', DataType::STRING)]],
78+
[['not ilike', 'name', 'heyho', 'conjunction' => LikeConjunction::Or], '"name" NOT ILIKE :qp0', [':qp0' => new Param('%heyho%', DataType::STRING)]],
7879

7980
/* ilike for many values */
8081
[
@@ -88,11 +89,11 @@ public static function buildCondition(): array
8889
[':qp0' => new Param('%heyho%', DataType::STRING), ':qp1' => new Param('%abc%', DataType::STRING)],
8990
],
9091
[
91-
['or ilike', 'name', ['heyho', 'abc']],
92+
['ilike', 'name', ['heyho', 'abc'], 'conjunction' => LikeConjunction::Or],
9293
'"name" ILIKE :qp0 OR "name" ILIKE :qp1', [':qp0' => new Param('%heyho%', DataType::STRING), ':qp1' => new Param('%abc%', DataType::STRING)],
9394
],
9495
[
95-
['or not ilike', 'name', ['heyho', 'abc']],
96+
['not ilike', 'name', ['heyho', 'abc'], 'conjunction' => LikeConjunction::Or],
9697
'"name" NOT ILIKE :qp0 OR "name" NOT ILIKE :qp1',
9798
[':qp0' => new Param('%heyho%', DataType::STRING), ':qp1' => new Param('%abc%', DataType::STRING)],
9899
],

0 commit comments

Comments
 (0)