Last active
August 29, 2015 14:21
-
-
Save stovak/1b608f9dc9f1f956a506 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 123e77bfa8983a27fe873a31868bfff83d548929 Mon Sep 17 00:00:00 2001 | |
From: Tom Stovall <[email protected]> | |
Date: Wed, 13 May 2015 11:51:53 -0700 | |
Subject: [PATCH] D7 backport: MySQL driver does not support full UTF-8 | |
(emojis, asian symbols, mathematical symbols) | |
--- | |
includes/database/mysql/database.inc | 9 ++++++--- | |
includes/database/mysql/schema.inc | 4 ++-- | |
2 files changed, 8 insertions(+), 5 deletions(-) | |
diff --git a/includes/database/mysql/database.inc b/includes/database/mysql/database.inc | |
index 0b84f27..54977d0 100644 | |
--- a/includes/database/mysql/database.inc | |
+++ b/includes/database/mysql/database.inc | |
@@ -27,6 +27,9 @@ class DatabaseConnection_mysql extends DatabaseConnection { | |
$this->transactionalDDLSupport = FALSE; | |
$this->connectionOptions = $connection_options; | |
+ | |
+ // allow the drupal default charset to be overridden in the settings.php database config | |
+ $charset = (array_key_exists('charset', $connection_options) ? $connection_options['charset'] : 'utf8'); | |
// The DSN should use either a socket or a host/port. | |
if (isset($connection_options['unix_socket'])) { | |
@@ -39,7 +42,7 @@ class DatabaseConnection_mysql extends DatabaseConnection { | |
// Character set is added to dsn to ensure PDO uses the proper character | |
// set when escaping. This has security implications. See | |
// https://www.drupal.org/node/1201452 for further discussion. | |
- $dsn .= ';charset=utf8'; | |
+ $dsn .= ';charset=' . $charset; | |
$dsn .= ';dbname=' . $connection_options['database']; | |
// Allow PDO options to be overridden. | |
$connection_options += array( | |
@@ -58,10 +61,10 @@ class DatabaseConnection_mysql extends DatabaseConnection { | |
// certain one has been set; otherwise, MySQL defaults to 'utf8_general_ci' | |
// for UTF-8. | |
if (!empty($connection_options['collation'])) { | |
- $this->exec('SET NAMES utf8 COLLATE ' . $connection_options['collation']); | |
+ $this->exec('SET NAMES ' . $charset . ' COLLATE ' . $connection_options['collation']); | |
} | |
else { | |
- $this->exec('SET NAMES utf8'); | |
+ $this->exec('SET NAMES ' . $charset); | |
} | |
// Set MySQL init_commands if not already defined. Default Drupal's MySQL | |
diff --git a/includes/database/mysql/schema.inc b/includes/database/mysql/schema.inc | |
index 2a2722e..6b1eea1 100644 | |
--- a/includes/database/mysql/schema.inc | |
+++ b/includes/database/mysql/schema.inc | |
@@ -77,11 +77,11 @@ class DatabaseSchema_mysql extends DatabaseSchema { | |
*/ | |
protected function createTableSql($name, $table) { | |
$info = $this->connection->getConnectionOptions(); | |
- | |
// Provide defaults if needed. | |
$table += array( | |
'mysql_engine' => 'InnoDB', | |
- 'mysql_character_set' => 'utf8', | |
+ // allow charset to be overridden in settings.php | |
+ 'mysql_character_set' => (array_key_exists('charset', $info) ? $info['charset'] : 'utf8'), | |
); | |
$sql = "CREATE TABLE {" . $name . "} (\n"; | |
-- | |
2.4.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Comments in lines 21 & 61 of your patch should start with a capital letter and end in a period. Also, make sure they wrap at 80 char.