During setup of a mysql database we try to detect if charset 'utf8mb4' can be used
This commit is contained in:
parent
3fd75e288c
commit
aa22f93018
1 changed files with 26 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue