Commit fe51314c authored by catch's avatar catch
Browse files

Issue #1237252 by bfroehle, drewish, Berdir: Fixed DB Case Sensitivity: Allow...

Issue #1237252 by bfroehle, drewish, Berdir: Fixed DB Case Sensitivity: Allow BINARY attribute in MySQL.
parent 1f4ececf
...@@ -140,8 +140,13 @@ protected function createTableSql($name, $table) { ...@@ -140,8 +140,13 @@ protected function createTableSql($name, $table) {
protected function createFieldSql($name, $spec) { protected function createFieldSql($name, $spec) {
$sql = "`" . $name . "` " . $spec['mysql_type']; $sql = "`" . $name . "` " . $spec['mysql_type'];
if (in_array($spec['mysql_type'], array('VARCHAR', 'CHAR', 'TINYTEXT', 'MEDIUMTEXT', 'LONGTEXT', 'TEXT')) && isset($spec['length'])) { if (in_array($spec['mysql_type'], array('VARCHAR', 'CHAR', 'TINYTEXT', 'MEDIUMTEXT', 'LONGTEXT', 'TEXT'))) {
$sql .= '(' . $spec['length'] . ')'; if (isset($spec['length'])) {
$sql .= '(' . $spec['length'] . ')';
}
if (!empty($spec['binary'])) {
$sql .= ' BINARY';
}
} }
elseif (isset($spec['precision']) && isset($spec['scale'])) { elseif (isset($spec['precision']) && isset($spec['scale'])) {
$sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')'; $sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')';
......
...@@ -80,6 +80,10 @@ ...@@ -80,6 +80,10 @@
* the precision (total number of significant digits) and scale * the precision (total number of significant digits) and scale
* (decimal digits right of the decimal point). Both values are * (decimal digits right of the decimal point). Both values are
* mandatory. Ignored for other field types. * 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 * All parameters apart from 'type' are optional except that type
* 'numeric' columns must specify 'precision' and 'scale', and type * 'numeric' columns must specify 'precision' and 'scale', and type
* 'varchar' must specify the 'length' parameter. * 'varchar' must specify the 'length' parameter.
......
...@@ -28,6 +28,7 @@ function database_test_schema() { ...@@ -28,6 +28,7 @@ function database_test_schema() {
'length' => 255, 'length' => 255,
'not null' => TRUE, 'not null' => TRUE,
'default' => '', 'default' => '',
'binary' => TRUE,
), ),
'age' => array( 'age' => array(
'description' => "The person's age", 'description' => "The person's age",
......
...@@ -3133,6 +3133,39 @@ class DatabaseBasicSyntaxTestCase extends DatabaseTestCase { ...@@ -3133,6 +3133,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. * Test invalid data handling.
*/ */
......
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