Return sqlite DB without case sensitivity
android, sqlite
Solution
It was answered here. Unfortunately is seems that you have to use the `rawQuery()` method instead of using the `query()` wrapper method. This method allows you to input raw SQL code that will be executed like so ...
db.rawQuery("SELECT " + Constants.KEY_ROWID + "," + Constants.KEY_BRAND + "," +
Constants.KEY_STOCK +
" FROM " + Constants.DATABASE_TABLE +
" ORDER BY " + Constants.KEY_BRAND + " COLLATE NOCASE ASC;", null);
Problem
I'm sitting here wondering how to sort my database without case sensitivity. Let's say I have 'A', 'a', 'B', 'b'. It will print like this: 'A', 'B', 'a', 'b'. but I want it sorted in a more human way. Here's my Cursor function: ``` /** * Return a Cursor over the list of all brands in the database * * @return Cursor over all brands sorted alphabetically + TODO: doesn't sort alphabetically because it's case sensitive */ public Cursor fetchAllBrands() { return mDb.query(Constants.DATABASE_TABLE, new String[] { Constants.KEY_ROWID, Constants.KEY_BRAND, Constants.KEY_STOCK }, null, null, null, null, Constants.KEY_BRAND); } ``` I have noticed that Java has `CASE_INSENSITIVE_ORDER`, but I have no idea how to implement it if that is the solution to this problem. Can anybody help me with this?