2

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

6
  • Your SQL query should be returning the data ordered by title. Something else would seem to be the problem. Commented Aug 24, 2014 at 14:06
  • 1
    Why do you think the result is wrong? How do you look at the results? Commented Aug 24, 2014 at 14:07
  • @CL. the result is sorting by _id (_id is a incremental field). For example, the result is like this: 1 Test 2 Abc Where 1, 2 are the _id and Test, Abc the title. Commented Aug 24, 2014 at 14:12
  • @GordonLinoff unfortunately the result isn't sorting well, I do a while Log(result) and it's sorting by _id :( Commented Aug 24, 2014 at 14:14
  • Show the code that runs the query and logs the result. Commented Aug 24, 2014 at 14:17

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

@evanwong what essential parts do you have in mind? Does the query not count?
Now it is better. By the way, I didn't vote you down.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.