Case insensitive sorting

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Case insensitive sorting

Postby Quetzalcoatl » Sat Nov 07, 2009 12:21 pm

Hi,

Is it possible to return a cursor using SQLiteDatabase's 'query' methods that sorts items regardless of case?

I'm currently returning a list of:

Apple
Banana
apple
banana

done by the following means:

Code: Select all
String sortField = "FIELD1";
String sortDir = " ASC"; //or desc

return db.query(DATABASE_TABLE, new String[] {ID_FIELD, FIELD1, FIELD2}, null, null, null, null, sortField + sortDir);


which would be better as:

Apple
apple
Banana
apple

Cheers,
Steve
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Top

Postby nmc » Sat Nov 07, 2009 12:43 pm

select * from items order by upper(title)
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby Quetzalcoatl » Sat Nov 07, 2009 1:20 pm

Thanks nmc, I've just tried using the db.rawQuery() to use an "ORDER BY title COLLATE NOCASE" which seems to work fine.

I will give your method a try as it looks a look cleaner than having a full SQL statement in the db.rawQuery.
:D
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 2 guests