Commit d58ac9fd authored by Dries's avatar Dries

- Patch #772678 by sun, jpmckinney, Berdir: database default collation is not respected.

parent 7c2bcffa
...@@ -47,8 +47,15 @@ public function __construct(array $connection_options = array()) { ...@@ -47,8 +47,15 @@ public function __construct(array $connection_options = array()) {
PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_CASE => PDO::CASE_LOWER,
)); ));
// Force MySQL to use the UTF-8 character set by default. // Force MySQL to use the UTF-8 character set. Also set the collation, if a
$this->exec('SET NAMES "utf8"'); // 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. // Force MySQL's behavior to conform more closely to SQL standards.
// This allows Drupal to run almost seamlessly on many different // This allows Drupal to run almost seamlessly on many different
......
...@@ -74,10 +74,12 @@ protected function buildTableNameCondition($table_name, $operator = '=') { ...@@ -74,10 +74,12 @@ protected function buildTableNameCondition($table_name, $operator = '=') {
* An array of SQL statements to create the table. * An array of SQL statements to create the table.
*/ */
protected function createTableSql($name, $table) { protected function createTableSql($name, $table) {
// Provide some defaults if needed $info = $this->connection->getConnectionOptions();
// Provide defaults if needed.
$table += array( $table += array(
'mysql_engine' => 'InnoDB', 'mysql_engine' => 'InnoDB',
'mysql_character_set' => 'UTF8', 'mysql_character_set' => 'utf8',
); );
$sql = "CREATE TABLE {" . $name . "} (\n"; $sql = "CREATE TABLE {" . $name . "} (\n";
...@@ -97,6 +99,13 @@ protected function createTableSql($name, $table) { ...@@ -97,6 +99,13 @@ protected function createTableSql($name, $table) {
$sql = substr($sql, 0, -3) . "\n) "; $sql = substr($sql, 0, -3) . "\n) ";
$sql .= 'ENGINE = ' . $table['mysql_engine'] . ' DEFAULT CHARACTER SET ' . $table['mysql_character_set']; $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. // Add table comment.
if (!empty($table['description'])) { if (!empty($table['description'])) {
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
* *
* Each database connection is specified as an array of settings, * Each database connection is specified as an array of settings,
* similar to the following: * similar to the following:
* * @code
* array( * array(
* 'driver' => 'mysql', * 'driver' => 'mysql',
* 'database' => 'databasename', * 'database' => 'databasename',
...@@ -62,7 +62,9 @@ ...@@ -62,7 +62,9 @@
* 'host' => 'localhost', * 'host' => 'localhost',
* 'port' => 3306, * 'port' => 3306,
* 'prefix' => 'myprefix_', * 'prefix' => 'myprefix_',
* 'collation' => 'utf8_general_ci',
* ); * );
* @endcode
* *
* The "driver" property indicates what Drupal database driver the * The "driver" property indicates what Drupal database driver the
* connection should use. This is usually the same as the name of the * connection should use. This is usually the same as the name of the
...@@ -86,11 +88,12 @@ ...@@ -86,11 +88,12 @@
* fall back to the single master server. * fall back to the single master server.
* *
* The general format for the $databases array is as follows: * The general format for the $databases array is as follows:
* * @code
* $databases['default']['default'] = $info_array; * $databases['default']['default'] = $info_array;
* $databases['default']['slave'][] = $info_array; * $databases['default']['slave'][] = $info_array;
* $databases['default']['slave'][] = $info_array; * $databases['default']['slave'][] = $info_array;
* $databases['extra']['default'] = $info_array; * $databases['extra']['default'] = $info_array;
* @endcode
* *
* In the above example, $info_array is an array of settings described above. * In the above example, $info_array is an array of settings described above.
* The first line sets a "default" database that has one master database * The first line sets a "default" database that has one master database
...@@ -100,7 +103,7 @@ ...@@ -100,7 +103,7 @@
* "extra". * "extra".
* *
* For a single database configuration, the following is sufficient: * For a single database configuration, the following is sufficient:
* * @code
* $databases['default']['default'] = array( * $databases['default']['default'] = array(
* 'driver' => 'mysql', * 'driver' => 'mysql',
* 'database' => 'databasename', * 'database' => 'databasename',
...@@ -108,7 +111,9 @@ ...@@ -108,7 +111,9 @@
* 'password' => 'password', * 'password' => 'password',
* 'host' => 'localhost', * 'host' => 'localhost',
* 'prefix' => 'main_', * 'prefix' => 'main_',
* 'collation' => 'utf8_general_ci',
* ); * );
* @endcode
* *
* You can optionally set prefixes for some or all database table names * You can optionally set prefixes for some or all database table names
* by using the 'prefix' setting. If a prefix is specified, the table * by using the 'prefix' setting. If a prefix is specified, the table
...@@ -117,14 +122,14 @@ ...@@ -117,14 +122,14 @@
* are desired, leave it as an empty string ''. * are desired, leave it as an empty string ''.
* *
* To have all database names prefixed, set 'prefix' as a string: * To have all database names prefixed, set 'prefix' as a string:
* * @code
* 'prefix' => 'main_', * 'prefix' => 'main_',
* * @endcode
* To provide prefixes for specific tables, set 'prefix' as an array. * To provide prefixes for specific tables, set 'prefix' as an array.
* The array's keys are the table names and the values are the prefixes. * The array's keys are the table names and the values are the prefixes.
* The 'default' element is mandatory and holds the prefix for any tables * The 'default' element is mandatory and holds the prefix for any tables
* not specified elsewhere in the array. Example: * not specified elsewhere in the array. Example:
* * @code
* 'prefix' => array( * 'prefix' => array(
* 'default' => 'main_', * 'default' => 'main_',
* 'users' => 'shared_', * 'users' => 'shared_',
...@@ -132,13 +137,13 @@ ...@@ -132,13 +137,13 @@
* 'role' => 'shared_', * 'role' => 'shared_',
* 'authmap' => 'shared_', * 'authmap' => 'shared_',
* ), * ),
* * @endcode
* You can also use a reference to a schema/database as a prefix. This maybe * You can also use a reference to a schema/database as a prefix. This maybe
* useful if your Drupal installation exists in a schema that is not the default * useful if your Drupal installation exists in a schema that is not the default
* or you want to access several databases from the same code base at the same * or you want to access several databases from the same code base at the same
* time. * time.
* Example: * Example:
* * @code
* 'prefix' => array( * 'prefix' => array(
* 'default' => 'main.', * 'default' => 'main.',
* 'users' => 'shared.', * 'users' => 'shared.',
...@@ -146,10 +151,11 @@ ...@@ -146,10 +151,11 @@
* 'role' => 'shared.', * 'role' => 'shared.',
* 'authmap' => 'shared.', * 'authmap' => 'shared.',
* ); * );
* * @endcode
* NOTE: MySQL and SQLite's definition of a schema is a database. * NOTE: MySQL and SQLite's definition of a schema is a database.
* *
* Database configuration format: * Database configuration format:
* @code
* $databases['default']['default'] = array( * $databases['default']['default'] = array(
* 'driver' => 'mysql', * 'driver' => 'mysql',
* 'database' => 'databasename', * 'database' => 'databasename',
...@@ -170,6 +176,7 @@ ...@@ -170,6 +176,7 @@
* 'driver' => 'sqlite', * 'driver' => 'sqlite',
* 'database' => '/path/to/databasefilename', * 'database' => '/path/to/databasefilename',
* ); * );
* @endcode
*/ */
$databases = array(); $databases = array();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment