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 @@
return $this->expressionBuilder->notLike($x, $y);
}

/**
* Creates a NOT ILIKE() comparison expression with the given arguments.
*
* @param string $x Field in string format to be inspected by NOT ILIKE() comparison.
* @param mixed $y Argument to be used in NOT ILIKE() comparison.
* @param mixed|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($this->functionBuilder->lower($x), $this->functionBuilder->lower($y));

Check failure on line 335 in lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ImplicitToStringCast

lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php:335:44: ImplicitToStringCast: Argument 1 of Doctrine\DBAL\Query\Expression\ExpressionBuilder::notLike expects string, but OCP\DB\QueryBuilder\IQueryFunction provided with a __toString method (see https://psalm.dev/060)
}

/**
* 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 @@
return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->collation . ' LIKE', $y);
}

#[\Override]
public function notILike(
string|IParameter|ILiteral|IQueryFunction $x,
string|IParameter|ILiteral|IQueryFunction $y,

Check failure on line 42 in lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php:42:45: MoreSpecificImplementedParamType: Argument 2 of OC\DB\QueryBuilder\ExpressionBuilder\MySqlExpressionBuilder::notILike has the more specific type 'OCP\DB\QueryBuilder\ILiteral|OCP\DB\QueryBuilder\IParameter|OCP\DB\QueryBuilder\IQueryFunction|string', expecting 'mixed' as defined by OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder::notILike (see https://psalm.dev/140)
int|string|null $type = null,

Check failure on line 43 in lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php:43:19: MoreSpecificImplementedParamType: Argument 3 of OC\DB\QueryBuilder\ExpressionBuilder\MySqlExpressionBuilder::notILike has the more specific type 'int|null|string', expecting 'mixed|null' as defined by OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder::notILike (see https://psalm.dev/140)
): string {
$x = $this->helper->quoteColumnName($x);
$y = $this->helper->quoteColumnName($y);
return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->collation . ' NOT LIKE', $y);
}

/**
* 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 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,

Check failure on line 147 in lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php:147:45: MoreSpecificImplementedParamType: Argument 2 of OC\DB\QueryBuilder\ExpressionBuilder\OCIExpressionBuilder::notILike has the more specific type 'OCP\DB\QueryBuilder\ILiteral|OCP\DB\QueryBuilder\IParameter|OCP\DB\QueryBuilder\IQueryFunction|string', expecting 'mixed' as defined by OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder::notILike (see https://psalm.dev/140)
int|string|null $type = null,

Check failure on line 148 in lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php:148:19: MoreSpecificImplementedParamType: Argument 3 of OC\DB\QueryBuilder\ExpressionBuilder\OCIExpressionBuilder::notILike has the more specific type 'int|null|string', expecting 'mixed|null' as defined by OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder::notILike (see https://psalm.dev/140)
): 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 @@
$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,

Check failure on line 64 in lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php:64:45: MoreSpecificImplementedParamType: Argument 2 of OC\DB\QueryBuilder\ExpressionBuilder\PgSqlExpressionBuilder::notILike has the more specific type 'OCP\DB\QueryBuilder\ILiteral|OCP\DB\QueryBuilder\IParameter|OCP\DB\QueryBuilder\IQueryFunction|string', expecting 'mixed' as defined by OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder::notILike (see https://psalm.dev/140)
int|string|null $type = null,

Check failure on line 65 in lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php:65:19: MoreSpecificImplementedParamType: Argument 3 of OC\DB\QueryBuilder\ExpressionBuilder\PgSqlExpressionBuilder::notILike has the more specific type 'int|null|string', expecting 'mixed|null' as defined by OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder::notILike (see https://psalm.dev/140)
): 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 @@
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,

Check failure on line 33 in lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php:33:45: MoreSpecificImplementedParamType: Argument 2 of OC\DB\QueryBuilder\ExpressionBuilder\SqliteExpressionBuilder::notILike has the more specific type 'OCP\DB\QueryBuilder\ILiteral|OCP\DB\QueryBuilder\IParameter|OCP\DB\QueryBuilder\IQueryFunction|string', expecting 'mixed' as defined by OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder::notILike (see https://psalm.dev/140)
int|string|null $type = null,

Check failure on line 34 in lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php:34:19: MoreSpecificImplementedParamType: Argument 3 of OC\DB\QueryBuilder\ExpressionBuilder\SqliteExpressionBuilder::notILike has the more specific type 'int|null|string', expecting 'mixed|null' as defined by OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder::notILike (see https://psalm.dev/140)
): 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