Completed
Push — stable13 ( 8a8eb6...70fe04 )
by Morris
62:41 queued 38:28
created

MySqlTools::isMariaDBWithLargePrefix()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 6
nop 1
dl 0
loc 12
rs 9.5555
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017, ownCloud GmbH
4
 *
5
 * @author Thomas Müller <[email protected]>
6
 *
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OC\DB;
24
25
use OCP\IDBConnection;
26
27
/**
28
* Various MySQL specific helper functions.
29
*/
30
class MySqlTools {
31
32
	/**
33
	 * @param Connection $connection
34
	 * @return bool
35
	 */
36
	public function supports4ByteCharset(IDBConnection $connection) {
37
		$variables = ['innodb_file_per_table' => 'ON'];
38
		if (!$this->isMariaDBWithLargePrefix($connection)) {
39
			$variables['innodb_file_format'] = 'Barracuda';
40
			$variables['innodb_large_prefix'] = 'ON';
41
		}
42
43
		foreach ($variables as $var => $val) {
44
			$result = $connection->executeQuery("SHOW VARIABLES LIKE '$var'");
45
			$row = $result->fetch();
46
			$result->closeCursor();
47
			if ($row === false) {
48
				return false;
49
			}
50
			if (strcasecmp($row['Value'], $val) !== 0) {
51
				return false;
52
			}
53
		}
54
		return true;
55
	}
56
57
	protected function isMariaDBWithLargePrefix(IDBConnection $connection) {
58
		$result = $connection->executeQuery('SELECT VERSION()');
59
		$row = strtolower($result->fetchColumn());
60
		$result->closeCursor();
61
62
		if ($row === false) {
63
			return false;
64
		}
65
66
		return strpos($row, 'maria') && version_compare($row, '10.3', '>=') ||
67
			strpos($row, 'maria') === false && version_compare($row, '8.0', '>=');
68
	}
69
}
70