From d58ac9fd645314d82b6ad1d07d4a626fda517bdb Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Tue, 20 Jul 2010 21:12:47 +0000 Subject: - Patch #772678 by sun, jpmckinney, Berdir: database default collation is not respected. --- includes/database/mysql/database.inc | 11 +++++++++-- includes/database/mysql/schema.inc | 13 +++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'includes') diff --git a/includes/database/mysql/database.inc b/includes/database/mysql/database.inc index 552d95b8d..a3d711840 100644 --- a/includes/database/mysql/database.inc +++ b/includes/database/mysql/database.inc @@ -47,8 +47,15 @@ class DatabaseConnection_mysql extends DatabaseConnection { PDO::ATTR_CASE => PDO::CASE_LOWER, )); - // Force MySQL to use the UTF-8 character set by default. - $this->exec('SET NAMES "utf8"'); + // Force MySQL to use the UTF-8 character set. Also set the collation, if a + // 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']); + } + else { + $this->exec('SET NAMES utf8'); + } // Force MySQL's behavior to conform more closely to SQL standards. // This allows Drupal to run almost seamlessly on many different diff --git a/includes/database/mysql/schema.inc b/includes/database/mysql/schema.inc index 7be5d0280..b018d2d9c 100644 --- a/includes/database/mysql/schema.inc +++ b/includes/database/mysql/schema.inc @@ -74,10 +74,12 @@ class DatabaseSchema_mysql extends DatabaseSchema { * An array of SQL statements to create the table. */ protected function createTableSql($name, $table) { - // Provide some defaults if needed + $info = $this->connection->getConnectionOptions(); + + // Provide defaults if needed. $table += array( 'mysql_engine' => 'InnoDB', - 'mysql_character_set' => 'UTF8', + 'mysql_character_set' => 'utf8', ); $sql = "CREATE TABLE {" . $name . "} (\n"; @@ -97,6 +99,13 @@ class DatabaseSchema_mysql extends DatabaseSchema { $sql = substr($sql, 0, -3) . "\n) "; $sql .= 'ENGINE = ' . $table['mysql_engine'] . ' DEFAULT CHARACTER SET ' . $table['mysql_character_set']; + // By default, MySQL uses the default collation for new tables, which is + // 'utf8_general_ci' for utf8. If an alternate collation has been set, it + // needs to be explicitly specified. + // @see DatabaseConnection_mysql + if (!empty($info['collation'])) { + $sql .= ' COLLATE ' . $info['collation']; + } // Add table comment. if (!empty($table['description'])) { -- cgit v1.2.3