Alex Rivera | Logout

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

Asked 2010-08-13T22:09:02.673
15

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 takes the locale into account, for example:

SELECT * from table WHERE name='sctzy' COLLATE LOCALIZED 

Will find the entry 'ščťžý'.

But using LIKE will fail:

SELECT * from table WHERE name LIKE '%sctzy%' COLLATE LOCALIZED 

No row is returned.

BTW. There is no java.text.Normalized class in Android. I thought I could make a second column with a normalized text, stripped of special characters, which would be used for searching - but I am missing a class or way how to normalize the String.

Edit
Report

1 Answer

0

Might be time consuming, but you can use the java.text.Normalizer like here

Converting Symbols, Accent Letters to English Alphabet

As is not part of the java subset that Android, you may try to look for it at the code of java, such as Normalizer.java With the Javadoc found here:

And copy the part of the code needed inside your project.

Hope it works!

answered 2012-05-04T09:22:08.750

Your Answer