summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-09-21 15:27:20 +0000
committerDries Buytaert <dries@buytaert.net>2008-09-21 15:27:20 +0000
commitd83a75125e0a63746ef426f47fa3fae5124cc642 (patch)
treea1bd96572c8a9b35609f25dc4373cfb4b276adb6
parent19329548f9084653ee4dbdc1dd289919d21f5aeb (diff)
downloadbrdo-d83a75125e0a63746ef426f47fa3fae5124cc642.tar.gz
brdo-d83a75125e0a63746ef426f47fa3fae5124cc642.tar.bz2
- Patch #310447 by Damien Tournoud, Crell, catch: add back SET NAMES='utf8' -- we love UTF-8
-rw-r--r--includes/database/mysql/database.inc6
-rw-r--r--modules/simpletest/tests/database_test.test34
2 files changed, 40 insertions, 0 deletions
diff --git a/includes/database/mysql/database.inc b/includes/database/mysql/database.inc
index a61fa9d9a..26fe17247 100644
--- a/includes/database/mysql/database.inc
+++ b/includes/database/mysql/database.inc
@@ -30,6 +30,12 @@ class DatabaseConnection_mysql extends DatabaseConnection {
// Because MySQL's prepared statements skip the query cache, because it's dumb.
PDO::ATTR_EMULATE_PREPARES => TRUE,
));
+
+ // Force MySQL to use the UTF-8 character set by default.
+ $this->exec('SET NAMES "utf8"');
+
+ // Enable MySQL's "strict mode", which removes most of MySQL's
+ // "just be lazy" behaviors that end up causing more trouble than they're worth.
$this->exec('SET sql_mode=STRICT_ALL_TABLES');
}
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index 17b838b71..c7b4f69d6 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -1569,3 +1569,37 @@ class DatabaseAlter2TestCase extends DatabaseTestCase {
}
}
}
+
+/**
+ * Regression tests.
+ */
+class DatabaseRegressionTestCase extends DatabaseTestCase {
+
+ function getInfo() {
+ return array(
+ 'name' => t('Regression tests'),
+ 'description' => t('Regression tests cases for the database layer.'),
+ 'group' => t('Database'),
+ );
+ }
+
+ /**
+ * Regression test for #310447.
+ *
+ * Tries to insert non-ascii UTF-8 data in a database column and checks
+ * if its stored properly.
+ */
+ function testRegression_310447() {
+ // That's a 255 character UTF-8 string.
+ $name = str_repeat("é", 255);
+ db_insert('test')
+ ->fields(array(
+ 'name' => $name,
+ 'age' => 20,
+ 'job' => 'Dancer',
+ ))->execute();
+
+ $from_database = db_query("SELECT name FROM {test} WHERE name = :name", array(':name' => $name))->fetchField();
+ $this->assertIdentical($name, $from_database, t("The database handles UTF-8 characters cleanly."));
+ }
+}