Using COLLATE in Android SQLite - Locales is ignored in LIKE statement

前端 未结 5 1126
梦谈多话
梦谈多话 2020-11-30 14:59

When creating my SQLite database in Android I set the database locale - db.setLocale(new Locale(\"cz_CZ\")). This is a Czech locale.

A SELECT statement works and tak

5条回答
  •  感情败类
    2020-11-30 15:26

    Creating a second normalised column can be used to go around limitations (as mentioned briefly in other answers).

    This means in practice that you have to create another (shadow) column of your first where the same data in a fixed case (e.g. all upper chars) is stored. Case insensitive queries (including like queries) can be made on this new column with search values in the same case.

    If the first column "a" contains

    AAA
    aaa
    Bbb
    äää
    ééé

    The second column a_shadow would contain for the same rows

    AAA
    AAA
    BBB
    ÄÄÄ
    ÉÉÉ

    and your original query (example) "select a from mytable where a='äää'"
    would be replaced with "select a from mytable where A='ÄÄÄ'"

    Your code needs to be updated to fill the converted shadow content when adding the primary content. If the column is added after creation or you cannot change the code existing values may need to be converted using an update query. Example:

    UPDATE mytable SET a_shadow=UPPER(a);

提交回复
热议问题