summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcatch2012-04-13 17:21:35 +0900
committercatch2012-04-13 17:21:35 +0900
commitfe51314cb8a539e646abb9f7fac2636c0cf7195a (patch)
tree8aa63d253d9fd5c48b4fd5742297736b65e0dacc
parent1f4ececf107f7a4b6751cd7a2abe6e75474f760b (diff)
Issue #1237252 by bfroehle, drewish, Berdir: Fixed DB Case Sensitivity: Allow BINARY attribute in MySQL.
-rw-r--r--core/lib/Drupal/Core/Database/Driver/mysql/Schema.php9
-rw-r--r--core/lib/Drupal/Core/Database/Schema.php4
-rw-r--r--core/modules/simpletest/tests/database_test.install1
-rw-r--r--core/modules/simpletest/tests/database_test.test33
4 files changed, 45 insertions, 2 deletions
diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
index f5e493d..2961aeb 100644
--- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
@@ -140,8 +140,13 @@ class Schema extends DatabaseSchema {
protected function createFieldSql($name, $spec) {
$sql = "`" . $name . "` " . $spec['mysql_type'];
- if (in_array($spec['mysql_type'], array('VARCHAR', 'CHAR', 'TINYTEXT', 'MEDIUMTEXT', 'LONGTEXT', 'TEXT')) && isset($spec['length'])) {
- $sql .= '(' . $spec['length'] . ')';
+ if (in_array($spec['mysql_type'], array('VARCHAR', 'CHAR', 'TINYTEXT', 'MEDIUMTEXT', 'LONGTEXT', 'TEXT'))) {
+ if (isset($spec['length'])) {
+ $sql .= '(' . $spec['length'] . ')';
+ }
+ if (!empty($spec['binary'])) {
+ $sql .= ' BINARY';
+ }
}
elseif (isset($spec['precision']) && isset($spec['scale'])) {
$sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')';
diff --git a/core/lib/Drupal/Core/Database/Schema.php b/core/lib/Drupal/Core/Database/Schema.php
index 9e2f22e..62e1327 100644
--- a/core/lib/Drupal/Core/Database/Schema.php
+++ b/core/lib/Drupal/Core/Database/Schema.php
@@ -80,6 +80,10 @@ use Drupal\Core\Database\Query\PlaceholderInterface;
* the precision (total number of significant digits) and scale
* (decimal digits right of the decimal point). Both values are
* mandatory. Ignored for other field types.
+ * - 'binary': A boolean indicating that MySQL should force 'char',
+ * 'varchar' or 'text' fields to use case-sensitive binary collation.
+ * This has no effect on other database types for which case sensitivity
+ * is already the default behavior.
* All parameters apart from 'type' are optional except that type
* 'numeric' columns must specify 'precision' and 'scale', and type
* 'varchar' must specify the 'length' parameter.
diff --git a/core/modules/simpletest/tests/database_test.install b/core/modules/simpletest/tests/database_test.install
index 4dce2b1..867d813 100644
--- a/core/modules/simpletest/tests/database_test.install
+++ b/core/modules/simpletest/tests/database_test.install
@@ -28,6 +28,7 @@ function database_test_schema() {
'length' => 255,
'not null' => TRUE,
'default' => '',
+ 'binary' => TRUE,
),
'age' => array(
'description' => "The person's age",
diff --git a/core/modules/simpletest/tests/database_test.test b/core/modules/simpletest/tests/database_test.test
index 04181b3..bec0c16 100644
--- a/core/modules/simpletest/tests/database_test.test
+++ b/core/modules/simpletest/tests/database_test.test
@@ -3134,6 +3134,39 @@ class DatabaseBasicSyntaxTestCase extends DatabaseTestCase {
}
/**
+ * Test case sensitivity handling.
+ */
+class DatabaseCaseSensitivityTestCase extends DatabaseTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Case sensitivity',
+ 'description' => 'Test handling case sensitive collation.',
+ 'group' => 'Database',
+ );
+ }
+
+ /**
+ * Test BINARY collation in MySQL.
+ */
+ function testCaseSensitiveInsert() {
+ $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
+
+ $john = db_insert('test')
+ ->fields(array(
+ 'name' => 'john', // <- A record already exists with name 'John'.
+ 'age' => 2,
+ 'job' => 'Baby',
+ ))
+ ->execute();
+
+ $num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
+ $this->assertIdentical($num_records_before + 1, (int) $num_records_after, t('Record inserts correctly.'));
+ $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'john'))->fetchField();
+ $this->assertIdentical($saved_age, '2', t('Can retrieve after inserting.'));
+ }
+}
+
+/**
* Test invalid data handling.
*/
class DatabaseInvalidDataTestCase extends DatabaseTestCase {