Felipe M
Felipe M

Reputation: 459

Android SQLite not Sorting

Do you know what's wrong about my try of sorting the SQLite results?

Here it's how I do on Java (Android):

return database.query("tools", new String[] {"_id","title"}, null, null, null, null, "title Asc");

Believe, I already tried this:

SELECT _id, title FROM tools ORDER BY title ASC

But in both ways, the SQL result is sort by the field _id ASC!

Don't know what to do anymore.

Thanks

[[EDIT]]

I looked at my results and I guess what's going on.

_id          title
 1            test
 2            Ábc
 3            Abcd

title has special characteres

Upvotes: 2

Views: 205

Answers (1)

Felipe M
Felipe M

Reputation: 459

I got the error. My title field has accents.

Problem described here: Problems ordering sqlite by a column with accented characters (Á)

Before:

SELECT _id, title FROM tools ORDER BY title ASC

After:

SELECT _id, title FROM tools ORDER BY title COLLATE UNICODE ASC

Note that "COLLATE UNICODE" ignores the current locale. The structure must be:

Order By COLUMN COLLATE UNICODE [ASC/DESC]

Reference:
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

Upvotes: 3

Related Questions