diff options
author | Robin Appelman <robin@icewind.nl> | 2017-12-20 15:51:37 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-12-20 15:51:37 +0100 |
commit | aad01894e38ff77781934c16b75dac43d49ec74a (patch) | |
tree | 2ee2e3354bf6987eea6dfb19a801cb6ac2987d6a /lib/private/DB | |
parent | ac14d02e1e23d8e31e11ed9729285d7fc5924543 (diff) | |
download | nextcloud-server-aad01894e38ff77781934c16b75dac43d49ec74a.tar.gz nextcloud-server-aad01894e38ff77781934c16b75dac43d49ec74a.zip |
refactor user searching
add additional user searching tests
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/DB')
4 files changed, 15 insertions, 4 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index b9ef447b74b..8a8a2f100ef 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -401,7 +401,7 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection { } /** - * Espace a parameter to be used in a LIKE query + * Escape a parameter to be used in a LIKE query * * @param string $param * @return string diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php index a32ae4a1827..85b676be3f4 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php @@ -26,6 +26,7 @@ namespace OC\DB\QueryBuilder\ExpressionBuilder; use Doctrine\DBAL\Query\Expression\ExpressionBuilder as DoctrineExpressionBuilder; use OC\DB\QueryBuilder\CompositeExpression; +use OC\DB\QueryBuilder\FunctionBuilder\FunctionBuilder; use OC\DB\QueryBuilder\Literal; use OC\DB\QueryBuilder\QueryFunction; use OC\DB\QueryBuilder\QuoteHelper; @@ -45,6 +46,9 @@ class ExpressionBuilder implements IExpressionBuilder { /** @var IDBConnection */ protected $connection; + /** @var FunctionBuilder */ + protected $functionBuilder; + /** * Initializes a new <tt>ExpressionBuilder</tt>. * @@ -54,6 +58,7 @@ class ExpressionBuilder implements IExpressionBuilder { $this->connection = $connection; $this->helper = new QuoteHelper(); $this->expressionBuilder = new DoctrineExpressionBuilder($connection); + $this->functionBuilder = $connection->getQueryBuilder()->func(); } /** @@ -298,9 +303,7 @@ class ExpressionBuilder implements IExpressionBuilder { * @since 9.0.0 */ public function iLike($x, $y, $type = null) { - $x = $this->helper->quoteColumnName($x); - $y = $this->helper->quoteColumnName($y); - return $this->expressionBuilder->comparison("LOWER($x)", 'LIKE', "LOWER($y)"); + return $this->expressionBuilder->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y)); } /** diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php index 14d8ad33e40..d9e8a1279cc 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php @@ -31,4 +31,8 @@ class SqliteExpressionBuilder extends ExpressionBuilder { public function like($x, $y, $type = null) { return parent::like($x, $y, $type) . " ESCAPE '\\'"; } + + public function iLike($x, $y, $type = null) { + return $this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y), $type); + } } diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php index 2789b8cb356..1d745306351 100644 --- a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php +++ b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php @@ -59,4 +59,8 @@ class FunctionBuilder implements IFunctionBuilder { public function sum($field) { return new QueryFunction('SUM(' . $this->helper->quoteColumnName($field) . ')'); } + + public function lower($field) { + return new QueryFunction('LOWER(' . $this->helper->quoteColumnName($field) . ')'); + } } |