Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ public function notLike($x, $y, $type = null): string {
return $this->expressionBuilder->notLike($x, $y);
}

/**
* Creates a NOT ILIKE() comparison expression with the given arguments.
*
* @param ILiteral|IParameter|IQueryFunction|string $x Field in string format to be inspected by NOT ILIKE() comparison.
* @param ILiteral|IParameter|IQueryFunction|string $y Argument to be used in NOT ILIKE() comparison.
* @param int|string|null $type one of the IQueryBuilder::PARAM_* constants
* required when comparing text fields for oci compatibility
*
* @return string
* @since 35.0.0
*/
#[\Override]
public function notILike(
string|IParameter|ILiteral|IQueryFunction $x,
string|IParameter|ILiteral|IQueryFunction $y,
int|string|null $type = null,
): string {
return $this->expressionBuilder->notLike((string)$this->functionBuilder->lower($x), (string)$this->functionBuilder->lower($y));
}

/**
* Creates a IN () comparison expression with the given arguments.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

use OC\DB\ConnectionAdapter;
use OC\DB\QueryBuilder\QueryFunction;
use OCP\DB\QueryBuilder\ILiteral;
use OCP\DB\QueryBuilder\IParameter;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use Psr\Log\LoggerInterface;
Expand All @@ -34,6 +36,17 @@ public function iLike($x, $y, $type = null): string {
return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->collation . ' LIKE', $y);
}

#[\Override]
public function notILike(
string|IParameter|ILiteral|IQueryFunction $x,
string|IParameter|ILiteral|IQueryFunction $y,
int|string|null $type = null,
): string {
$x = $this->helper->quoteColumnName($x);
$y = $this->helper->quoteColumnName($y);
return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->collation . ' NOT LIKE', $y);
Comment on lines +45 to +47

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is not ILIKE and has to lower() call either, is it the right implementation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good question, I noticed that as well. But this implemented according to the current iLike method.

Should I remove overrides for both methods then (as parent already has lower() call)?

}

/**
* Returns a IQueryFunction that casts the column to the given type
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,13 @@ public function like($x, $y, $type = null): string {
public function iLike($x, $y, $type = null): string {
return $this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y));
}

#[\Override]
public function notILike(
string|IParameter|ILiteral|IQueryFunction $x,
string|IParameter|ILiteral|IQueryFunction $y,
int|string|null $type = null,
): string {
return $this->notLike($this->functionBuilder->lower($x), $this->functionBuilder->lower($y));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,15 @@ public function iLike($x, $y, $type = null): string {
$y = $this->helper->quoteColumnName($y);
return $this->expressionBuilder->comparison($x, 'ILIKE', $y);
}

#[\Override]
public function notILike(
string|IParameter|ILiteral|IQueryFunction $x,
string|IParameter|ILiteral|IQueryFunction $y,
int|string|null $type = null,
): string {
$x = $this->helper->quoteColumnName($x);
$y = $this->helper->quoteColumnName($y);
return $this->expressionBuilder->comparison($x, 'NOT ILIKE', $y);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public function iLike($x, $y, $type = null): string {
return $this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y), $type);
}

#[\Override]
public function notILike(
string|IParameter|ILiteral|IQueryFunction $x,
string|IParameter|ILiteral|IQueryFunction $y,
int|string|null $type = null,
): string {
return $this->notLike($this->functionBuilder->lower($x), $this->functionBuilder->lower($y), $type);
}

/**
* @param mixed $column
* @param mixed|null $type
Expand Down
18 changes: 18 additions & 0 deletions lib/public/DB/QueryBuilder/IExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,24 @@ public function notLike($x, $y, $type = null): string;
*/
public function iLike($x, $y, $type = null): string;

/**
* Creates a NOT ILIKE() comparison expression with the given arguments.
*
* @param ILiteral|IParameter|IQueryFunction|string $x Field in string format to be inspected by NOT LIKE() comparison.
* @param ILiteral|IParameter|IQueryFunction|string $y Argument to be used in NOT ILIKE() comparison.
* @param IQueryBuilder::PARAM_*|null $type one of the IQueryBuilder::PARAM_* constants
* required when comparing text fields for oci compatibility
*
*
* @return string
* @since 35.0.0
*
* @psalm-taint-sink sql $x
* @psalm-taint-sink sql $y
* @psalm-taint-sink sql $type
*/
public function notILike(string|IParameter|ILiteral|IQueryFunction $x, string|IParameter|ILiteral|IQueryFunction $y, int|string|null $type = null): string;

/**
* Creates a IN () comparison expression with the given arguments.
*
Expand Down
37 changes: 37 additions & 0 deletions tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,43 @@ public function testILike($param1, $param2, $match): void {
$this->assertEquals($match, $column);
}

public static function notILikeProvider(): array {
$connection = Server::get(IDBConnection::class);

return [
['foo', 'bar', true],
['foo', 'foo', false],
['foo', 'Foo', false],
['foo', 'f%', false],
['foo', '%o', false],
['foo', '%', false],
['foo', 'fo_', false],
['foo', 'foo_', true],
['foo', $connection->escapeLikeParameter('fo_'), true],
['foo', $connection->escapeLikeParameter('f%'), true],
];
}

/**
*
* @param string $param1
* @param string $param2
* @param boolean $match
*/
#[\PHPUnit\Framework\Attributes\DataProvider('notILikeProvider')]
public function testNotILike($param1, $param2, $match): void {
$query = $this->connection->getQueryBuilder();

$query->select(new Literal('1'))
->from('users')
->where($query->expr()->notILike($query->createNamedParameter($param1), $query->createNamedParameter($param2)));

$result = $query->executeQuery();
$column = $result->fetchOne();
$result->closeCursor();
$this->assertEquals($match, $column);
}

public function testCastColumn(): void {
$appId = $this->getUniqueID('testing');
$this->createConfig($appId, '1', '4');
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ public function testNotLike(string $input, bool $isLiteral): void {
);
}

public function testILike(): void {
// iLike is implemented using lower() on both sides, so we just verify it returns a string
$result = $this->expressionBuilder->iLike('test', 'value');
$this->assertIsString($result);
}

public function testNotILike(): void {
// notILike is implemented using notLike with lower() on both sides, so we just verify it returns a string
$result = $this->expressionBuilder->notILike('test', 'value');
$this->assertIsString($result);
}

public static function dataIn(): array {
return [
['value', false],
Expand Down Expand Up @@ -294,6 +306,10 @@ public static function dataClobComparisons(): array {
['like', 'under\_%', IQueryBuilder::PARAM_STR, false, 1],
['notLike', '%5%', IQueryBuilder::PARAM_STR, false, 8],
['notLike', '%5%', IQueryBuilder::PARAM_STR, true, 6],
['iLike', '%5%', IQueryBuilder::PARAM_STR, false, 3],
['iLike', '%5%', IQueryBuilder::PARAM_STR, true, 1],
['notILike', '%5%', IQueryBuilder::PARAM_STR, false, 8],
['notILike', '%5%', IQueryBuilder::PARAM_STR, true, 6],
['in', ['5'], IQueryBuilder::PARAM_STR_ARRAY, false, 3],
['in', ['5'], IQueryBuilder::PARAM_STR_ARRAY, true, 1],
['notIn', ['5'], IQueryBuilder::PARAM_STR_ARRAY, false, 8],
Expand Down
Loading