Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- New #307: Add parameters `$ifExists` and `$cascade` to `CommandInterface::dropTable()` and
`DDLQueryBuilderInterface::dropTable()` methods (@vjik)
- Chg #310: Remove usage of `hasLimit()` and `hasOffset()` methods of `DQLQueryBuilder` class (@Tigrov)
- New #311: Add `caseSensitive` option to like condition (@vjik)

## 1.3.0 March 21, 2024

Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\Php73\Rector\String_\SensitiveHereNowDocRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
Expand All @@ -30,5 +31,6 @@
NullToStrictStringFuncCallArgRector::class,
ReadOnlyPropertyRector::class,
SensitiveHereNowDocRector::class,
RemoveParentCallWithoutParentRector::class,
]);
};
27 changes: 27 additions & 0 deletions src/Builder/LikeConditionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Db\Oracle\Builder;

use Exception;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\QueryBuilder\Condition\Interface\LikeConditionInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Quoter;
Expand Down Expand Up @@ -49,6 +50,32 @@ public function build(LikeConditionInterface $expression, array &$params = []):
return parent::build($expression, $params);
}

protected function prepareColumn(LikeConditionInterface $expression, array &$params): string
{
$column = parent::prepareColumn($expression, $params);

if ($expression->getCaseSensitive() === false) {
$column = 'LOWER(' . $column . ')';
}

return $column;
}

protected function preparePlaceholderName(
string|ExpressionInterface $value,
LikeConditionInterface $expression,
?array $escape,
array &$params,
): string {
$placeholderName = parent::preparePlaceholderName($value, $expression, $escape, $params);

if ($expression->getCaseSensitive() === false) {
$placeholderName = 'LOWER(' . $placeholderName . ')';
}

return $placeholderName;
}

/**
* @return string Character used to escape special characters in `LIKE` conditions. By default, it's assumed to be
* `!`.
Expand Down
6 changes: 4 additions & 2 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Yiisoft\Db\Oracle\Tests\Provider;

use Exception;
use Yiisoft\Db\Command\Param;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\DataType;
use Yiisoft\Db\Constant\PseudoType;
use Yiisoft\Db\Constant\ReferentialAction;
use Yiisoft\Db\Constraint\ForeignKeyConstraint;
Expand Down Expand Up @@ -75,14 +77,14 @@ public static function buildCondition(): array
{
$buildCondition = parent::buildCondition();

$buildCondition['like-custom-1'] = [['like', 'a', 'b'], '"a" LIKE :qp0 ESCAPE \'!\'', [':qp0' => '%b%']];
$buildCondition['like-custom-1'] = [['like', 'a', 'b'], '"a" LIKE :qp0 ESCAPE \'!\'', [':qp0' => new Param('%b%', DataType::STRING)]];
$buildCondition['like-custom-2'] = [
['like', 'a', new Expression(':qp0', [':qp0' => '%b%'])],
'"a" LIKE :qp0 ESCAPE \'!\'',
[':qp0' => '%b%'],
];
$buildCondition['like-custom-3'] = [
['like', new Expression('CONCAT(col1, col2)'), 'b'], 'CONCAT(col1, col2) LIKE :qp0 ESCAPE \'!\'', [':qp0' => '%b%'],
['like', new Expression('CONCAT(col1, col2)'), 'b'], 'CONCAT(col1, col2) LIKE :qp0 ESCAPE \'!\'', [':qp0' => new Param('%b%', DataType::STRING)],
];

return $buildCondition;
Expand Down
9 changes: 1 addition & 8 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,7 @@ public function testBatchInsert(
parent::testBatchInsert($table, $rows, $columns, $expected, $expectedParams);
}

/**
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\QueryBuilderProvider::buildCondition
*
* @throws Exception
* @throws InvalidConfigException
* @throws InvalidArgumentException
* @throws NotSupportedException
*/
#[DataProviderExternal(QueryBuilderProvider::class, 'buildCondition')]
public function testBuildCondition(
array|ExpressionInterface|string $condition,
string|null $expected,
Expand Down
Loading