diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2021-09-09 19:39:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-09 19:39:30 +0200 |
commit | 5c1b40ec36ecffa80fb8efb3fa3b439d9f89d69e (patch) | |
tree | faae0a95593671e175716090b6a25ec50140e5fc /lib | |
parent | 9be939300ae0e426d9818756f83f6f09733307fe (diff) | |
parent | ce283c12b6ba8d27dc0d2934ffe7d6f7b6743a02 (diff) | |
download | nextcloud-server-5c1b40ec36ecffa80fb8efb3fa3b439d9f89d69e.tar.gz nextcloud-server-5c1b40ec36ecffa80fb8efb3fa3b439d9f89d69e.zip |
Merge pull request #28677 from nextcloud/fix/noid/mysql-collation
make it possible to override the default collation on mysql
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/DB/AdapterMySQL.php | 12 | ||||
-rw-r--r-- | lib/private/DB/ConnectionFactory.php | 4 | ||||
-rw-r--r-- | lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php | 6 |
3 files changed, 13 insertions, 9 deletions
diff --git a/lib/private/DB/AdapterMySQL.php b/lib/private/DB/AdapterMySQL.php index 43da88b4b74..b4be5c2e96a 100644 --- a/lib/private/DB/AdapterMySQL.php +++ b/lib/private/DB/AdapterMySQL.php @@ -25,7 +25,7 @@ namespace OC\DB; class AdapterMySQL extends Adapter { /** @var string */ - protected $charset; + protected $collation; /** * @param string $tableName @@ -39,16 +39,16 @@ class AdapterMySQL extends Adapter { } public function fixupStatement($statement) { - $statement = str_replace(' ILIKE ', ' COLLATE ' . $this->getCharset() . '_general_ci LIKE ', $statement); + $statement = str_replace(' ILIKE ', ' COLLATE ' . $this->getCollation() . ' LIKE ', $statement); return $statement; } - protected function getCharset() { - if (!$this->charset) { + protected function getCollation(): string { + if (!$this->collation) { $params = $this->conn->getParams(); - $this->charset = isset($params['charset']) ? $params['charset'] : 'utf8'; + $this->collation = $params['collation'] ?? (($params['charset'] ?? 'utf8') . '_general_ci'); } - return $this->charset; + return $this->collation; } } diff --git a/lib/private/DB/ConnectionFactory.php b/lib/private/DB/ConnectionFactory.php index 53e488b5f09..b4c7597f6d4 100644 --- a/lib/private/DB/ConnectionFactory.php +++ b/lib/private/DB/ConnectionFactory.php @@ -89,6 +89,10 @@ class ConnectionFactory { if ($this->config->getValue('mysql.utf8mb4', false)) { $this->defaultConnectionParams['mysql']['charset'] = 'utf8mb4'; } + $collationOverride = $this->config->getValue('mysql.collation', null); + if ($collationOverride) { + $this->defaultConnectionParams['mysql']['collation'] = $collationOverride; + } } /** diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php index 3a0f45bcde7..e917ad3ad3a 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php @@ -31,7 +31,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder; class MySqlExpressionBuilder extends ExpressionBuilder { /** @var string */ - protected $charset; + protected $collation; /** * @param ConnectionAdapter $connection @@ -41,7 +41,7 @@ class MySqlExpressionBuilder extends ExpressionBuilder { parent::__construct($connection, $queryBuilder); $params = $connection->getInner()->getParams(); - $this->charset = isset($params['charset']) ? $params['charset'] : 'utf8'; + $this->collation = $params['collation'] ?? (($params['charset'] ?? 'utf8') . '_general_ci'); } /** @@ -50,6 +50,6 @@ class MySqlExpressionBuilder extends ExpressionBuilder { public function iLike($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->charset . '_general_ci LIKE', $y); + return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->collation . ' LIKE', $y); } } |