MDL-51052 dml: support for sql_like() under utf8_bin

This commit is contained in:
Charles Fulton 2015-08-11 12:35:09 +00:00 committed by David Monllao
parent d230899db8
commit 3d47155643
2 changed files with 11 additions and 1 deletions

View File

@ -1523,7 +1523,12 @@ class mysqli_native_moodle_database extends moodle_database {
if ($accentsensitive) {
return "LOWER($fieldname) $LIKE LOWER($param) COLLATE utf8_bin ESCAPE '$escapechar'";
} else {
return "$fieldname $LIKE $param ESCAPE '$escapechar'";
// Set a case sensitive collation if using utf8_bin.
if ($this->get_dbcollation() == 'utf8_bin') {
return "$fieldname $LIKE $param COLLATE utf8_unicode_ci ESCAPE '$escapechar'";
} else {
return "$fieldname $LIKE $param ESCAPE '$escapechar'";
}
}
}
}

View File

@ -3870,6 +3870,11 @@ class core_dml_testcase extends database_driver_testcase {
$records = $DB->get_records_sql($sql, array('aui'));
$this->assertCount(1, $records);
// Test LIKE under unusual collations.
$sql = "SELECT * FROM {{$tablename}} WHERE ".$DB->sql_like('name', '?', false, false);
$records = $DB->get_records_sql($sql, array("%dup_r%"));
$this->assertCount(2, $records);
$sql = "SELECT * FROM {{$tablename}} WHERE ".$DB->sql_like('name', '?', true, true, true); // NOT LIKE.
$records = $DB->get_records_sql($sql, array("%o%"));
$this->assertCount(3, $records);