Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

MySQL collation

Name: Anonymous 2008-04-25 5:41

Sup,

I'm currently struggling to have my rows sorted in a MySQL database. I'm trying to get 'é' handled like 'e' when it comes to sorting. Instead, I get it either at the start or the end of the list (tried a few collations) or between 'a' and 'b' (with utf8_general_ci). I can understand why it could be taken as first or last element but why it sits in the middle of nowhere is completely beyond me but if anyone knows a collation that could help me, please tell me.

Test case:
create database test charset utf8 collate utf8_general_ci;
create table test.test (
    id int unsigned auto_increment primary key,
    name varchar(255) charset utf8 collate utf8_general_ci
) engine=InnoDB charset utf8 collate utf8_general_ci;
insert into test.test value (1,'aa'),(2,'ab'),(3,'bb'),(4,'ea'),(5, 'éb'),(6, 'ec');
select * from test.test order by name;
select * from test.test order by id;
drop database test;

Expected result: both selects should have the same result set.

Name: Anonymous 2008-04-25 19:40


public static string RemoveAccents(string str) {
    if (str == null)
        return null;

    StringBuilder sb = new StringBuilder();
    bool changed = false;

    foreach (char c in str.Normalize(NormalizationForm.FormD))
        if (char.GetUnicodeCategory(c) != System.Globalization.UnicodeCategory.NonSpacingMark)
            sb.Append(c);
        else
            changed = true;

    if (changed)
        return sb.ToString().Normalize();

    return str;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List