Completed
Pull Request — master (#32372)
by Thomas
09:34
created

MySqlExpressionBuilder::iLike()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Thomas Müller <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2018, ownCloud GmbH
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OC\DB\QueryBuilder\ExpressionBuilder;
23
24
use OC\DB\QueryBuilder\QueryFunction;
25
26
class MySqlExpressionBuilder extends ExpressionBuilder {
27
28
	/**
29
	 * @inheritdoc
30
	 */
31
	public function like($x, $y, $type = null) {
32
		$x = $this->helper->quoteColumnName($x);
33
		$y = $this->helper->quoteColumnName($y);
34
		return $this->expressionBuilder->like($x, $y);
35
	}
36
37
	/**
38
	 * @inheritdoc
39
	 */
40
	public function iLike($x, $y, $type = null) {
41
		$x = $this->helper->quoteColumnName($x);
42
		$y = $this->helper->quoteColumnName($y);
43
44
		$characterSet = \OC::$server->getConfig()->getSystemValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8';
45
		return $this->expressionBuilder->comparison($x, " COLLATE {$characterSet}_general_ci LIKE", $y);
46
	}
47
48
	/**
49
	 * Use CHAR_LENGTH on MySQL to return number of characters not bytes.
50
	 * @inheritdoc
51
	 */
52
	public function length($column) {
53
		$column = $this->helper->quoteColumnName($column);
54
		return new QueryFunction("CHAR_LENGTH({$column})");
55
	}
56
}
57