add support for escaping like parameters when using the query builder
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
83f3990e06
commit
a65652fc1e
|
@ -153,6 +153,13 @@ class OCIExpressionBuilder extends ExpressionBuilder {
|
|||
return parent::castColumn($column, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function like($x, $y, $type = null) {
|
||||
return parent::like($x, $y, $type) . " ESCAPE '\\'";
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Robin Appelman <robin@icewind.nl>
|
||||
*
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC\DB\QueryBuilder\ExpressionBuilder;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
class SqliteExpressionBuilder extends ExpressionBuilder {
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function like($x, $y, $type = null) {
|
||||
return parent::like($x, $y, $type) . " ESCAPE '\\'";
|
||||
}
|
||||
}
|
|
@ -26,11 +26,15 @@ namespace OC\DB\QueryBuilder;
|
|||
|
||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
|
||||
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
||||
use OC\DB\OracleConnection;
|
||||
use OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder;
|
||||
use OC\DB\QueryBuilder\ExpressionBuilder\MySqlExpressionBuilder;
|
||||
use OC\DB\QueryBuilder\ExpressionBuilder\OCIExpressionBuilder;
|
||||
use OC\DB\QueryBuilder\ExpressionBuilder\PgSqlExpressionBuilder;
|
||||
use OC\DB\QueryBuilder\ExpressionBuilder\SqliteExpressionBuilder;
|
||||
use OC\DB\QueryBuilder\FunctionBuilder\FunctionBuilder;
|
||||
use OC\DB\QueryBuilder\FunctionBuilder\SqliteFunctionBuilder;
|
||||
use OC\SystemConfig;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\DB\QueryBuilder\IQueryFunction;
|
||||
|
@ -110,6 +114,8 @@ class QueryBuilder implements IQueryBuilder {
|
|||
return new PgSqlExpressionBuilder($this->connection);
|
||||
} else if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
|
||||
return new MySqlExpressionBuilder($this->connection);
|
||||
} else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
|
||||
return new SqliteExpressionBuilder($this->connection);
|
||||
} else {
|
||||
return new ExpressionBuilder($this->connection);
|
||||
}
|
||||
|
|
|
@ -352,24 +352,26 @@ class ExpressionBuilderTest extends TestCase {
|
|||
return [
|
||||
['eq', '5', IQueryBuilder::PARAM_STR, false, 3],
|
||||
['eq', '5', IQueryBuilder::PARAM_STR, true, 1],
|
||||
['neq', '5', IQueryBuilder::PARAM_STR, false, 6],
|
||||
['neq', '5', IQueryBuilder::PARAM_STR, true, 4],
|
||||
['neq', '5', IQueryBuilder::PARAM_STR, false, 8],
|
||||
['neq', '5', IQueryBuilder::PARAM_STR, true, 6],
|
||||
['lt', '5', IQueryBuilder::PARAM_STR, false, 3],
|
||||
['lt', '5', IQueryBuilder::PARAM_STR, true, 1],
|
||||
['lte', '5', IQueryBuilder::PARAM_STR, false, 6],
|
||||
['lte', '5', IQueryBuilder::PARAM_STR, true, 4],
|
||||
['gt', '5', IQueryBuilder::PARAM_STR, false, 3],
|
||||
['gt', '5', IQueryBuilder::PARAM_STR, false, 5],
|
||||
['gt', '5', IQueryBuilder::PARAM_STR, true, 1],
|
||||
['gte', '5', IQueryBuilder::PARAM_STR, false, 6],
|
||||
['gte', '5', IQueryBuilder::PARAM_STR, false, 8],
|
||||
['gte', '5', IQueryBuilder::PARAM_STR, true, 4],
|
||||
['like', '%5%', IQueryBuilder::PARAM_STR, false, 3],
|
||||
['like', '%5%', IQueryBuilder::PARAM_STR, true, 1],
|
||||
['notLike', '%5%', IQueryBuilder::PARAM_STR, false, 6],
|
||||
['notLike', '%5%', IQueryBuilder::PARAM_STR, true, 4],
|
||||
['like', 'under_%', IQueryBuilder::PARAM_STR, false, 2],
|
||||
['like', 'under\_%', IQueryBuilder::PARAM_STR, false, 1],
|
||||
['notLike', '%5%', IQueryBuilder::PARAM_STR, false, 8],
|
||||
['notLike', '%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, 6],
|
||||
['notIn', ['5'], IQueryBuilder::PARAM_STR_ARRAY, true, 4],
|
||||
['notIn', ['5'], IQueryBuilder::PARAM_STR_ARRAY, false, 8],
|
||||
['notIn', ['5'], IQueryBuilder::PARAM_STR_ARRAY, true, 6],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -392,6 +394,8 @@ class ExpressionBuilderTest extends TestCase {
|
|||
$this->createConfig($appId, 7, 4);
|
||||
$this->createConfig($appId, 8, 5);
|
||||
$this->createConfig($appId, 9, 6);
|
||||
$this->createConfig($appId, 10, 'under_score');
|
||||
$this->createConfig($appId, 11, 'underscore');
|
||||
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$query->select($query->createFunction('COUNT(*) AS `count`'))
|
||||
|
|
Loading…
Reference in New Issue