Commit f8e0b4ec authored by Charles Fulton's avatar Charles Fulton Committed by David Monllaó
Browse files

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

parent a91caeef
......@@ -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'";
}
}
}
}
......
......@@ -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);
......
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