Valentin Grégoire Valentin Grégoire - 1 year ago 124
Android Question

SQLite select all tables DESC

I have found the solution to get all tables in SQLite here.
How do I list the tables in a SQLite database file
However, when I change:

SELECT name FROM sqlite_master WHERE type='table';


SELECT name FROM sqlite_master WHERE type='table' ORDER BY name DESC;

the output is completely weird.
The first query gives me:
tbl201306 --> only 1 table so far, for June 2013.
The second query gives me:
android_metadata --> the name is not changed, but it returns this name.

I want to have these tables in descending order because in the future, the newest table would be on the top then.

My complete code:

public ArrayList<String> getDBTables() {
ArrayList<String> toReturn = new ArrayList<String>();
try {
Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name DESC", null);

while (c.moveToNext()) {
catch(SQLiteException e) {
return toReturn;

Answer Source

Your code skips over the first returned record.

You can either

  • keep the call to moveToFirst(), and change the loop into a do { ... } while (); loop, or
  • just remove the call to moveToFirst().
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download