What does COLLATE LOCALIZED ASC stand for?

狂风中的少年 提交于 2019-12-21 03:12:07

问题


private Cursor getContacts()
    {
        // Run query
        Uri uri = ContactsContract.Contacts.CONTENT_URI;
        String[] projection = new String[] {
                ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME
        };
        String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" +
                (mShowInvisible ? "0" : "1") + "'";
        String[] selectionArgs = null;
        String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

        return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
    }

What does COLLATE LOCALIZED ASC stand for?


回答1:


Collate is just fancy speak for sort (well sort of). So this is sort ordering based on localized preferences (i.e. current language's alphabet and conventions) in ascending order.




回答2:


It instructs SQLite to sort non-ASCII characters appropriately. Chars with diacritics (some call them accents) have higher byte codes than the character Z, so a plain ASCII sort wouldn't fit to many foreign languages.

For example, the capital A char's byte code is 0x41 and the capital Z char's is 0x5A. Then we have the Á (capital A accute) which code in Unicode is 0x00C1. So a plain byte code sort would result the Á to be after the Z.

But in languages that have this kind of characters the convention is to put those with diacritics as if they didn't have the diacritic. So the Á should be together with the plain A, at least before B.

And to illustrate, we have below a list of names sorted using their bytecode:

  • Brenda
  • Debby
  • George
  • Álvaro
  • Érico

Now using the COLLATE LOCALIZED it would sort by the "base" of the character:

  • Álvaro
  • Brenda
  • Debby
  • Érico
  • George



回答3:


COLLATE is an SQL operator that lets you override the default sort order for strings. For example, "COLLATE NOCASE" does case-insensitive comparison, and "COLLATE BINARY" does a case-sensitive comparison.

The SQLite C interface lets you define custom collations (http://www.sqlite.org/c3ref/create_collation.html).



来源:https://stackoverflow.com/questions/2380706/what-does-collate-localized-asc-stand-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!