erdomester
erdomester

Reputation: 11829

Android order sqlite table with capitalized and non-capitalized first letter

I query certain tables of an sqlite database:

public Cursor showAllTables(){
        String mySql = " SELECT name FROM sqlite_master " + " WHERE type='table'             "
                + "   AND name LIKE 'PR_%' ORDER BY name";
        return ourDatabase.rawQuery(mySql, null);
    }

I get this result:

How can I have the list ordered independently of the first letter being capital or not?

Upvotes: 2

Views: 878

Answers (2)

azertiti
azertiti

Reputation: 3150

You can try this:

public Cursor showAllTables(){
    String mySql = " SELECT name FROM sqlite_master " + " WHERE type='table'             "
                    + "   AND name LIKE 'PR_%' ORDER BY lower(name)";
    return ourDatabase.rawQuery(mySql, null);
}

I changed only name with lower(name).

Upvotes: 2

SeeSharp
SeeSharp

Reputation: 2800

You'll need to add COLLATE NOCASE to the end of your query:

public Cursor showAllTables(){
        String mySql = " SELECT name FROM sqlite_master " + " WHERE type='table'             "
                + "   AND name LIKE 'PR_%' ORDER BY name COLLATE NOCASE";
        return ourDatabase.rawQuery(mySql, null);
    }

Or you could recreate the table and add COLLATE NOCASE to the column definition.

Upvotes: 3

Related Questions