During setup of a mysql database we try to detect if charset 'utf8mb4' can be used

This commit is contained in:
Thomas Müller 2017-02-03 15:38:48 +01:00 committed by Roeland Jago Douma
parent 3fd75e288c
commit aa22f93018
No known key found for this signature in database
GPG key ID: F941078878347C0C

View file

@ -27,6 +27,7 @@
*/
namespace OC\Setup;
use OC\DB\ConnectionFactory;
use OCP\IDBConnection;
class MySQL extends AbstractDatabase {
@ -36,6 +37,12 @@ class MySQL extends AbstractDatabase {
//check if the database user has admin right
$connection = $this->connect(['dbname' => null]);
// detect mb4
if (is_null($this->config->getSValue('mysql.utf8mb4', null)) && $this->supports4ByteCharset($connection)) {
$this->config->setValue('mysql.utf8mb4', true);
$connection = $this->connect();
}
$this->createSpecificUser($username, $connection);
//create the database
@ -162,4 +169,23 @@ class MySQL extends AbstractDatabase {
'dbpassword' => $this->dbPassword,
]);
}
/**
* @param IDBConnection $connection
* @return bool
*/
private function supports4ByteCharset(IDBConnection $connection) {
foreach (['innodb_file_format' => 'Barracuda', 'innodb_large_prefix' => 'ON', 'innodb_file_per_table' => 'ON'] as $var => $val) {
$result = $connection->executeQuery("SHOW VARIABLES LIKE '$var'");
$rows = $result->fetch();
$result->closeCursor();
if ($rows === false) {
return false;
}
if (strcasecmp($rows['Value'], $val) === 0) {
return false;
}
}
return true;
}
}