Android gets a list of tables

Does anyone know SQL to get a list of table names through code in Android? I know that it .tablesdoes this through the shell, but it does not work through the code. Does this have anything to do with metadata, etc.?

+5
source share
2 answers

Got this:

SELECT * FROM sqlite_master WHERE type='table'
+3
source

It was just necessary to do the same. This seems to work:

public ArrayList<Object> listTables()
    {
        ArrayList<Object> tableList = new ArrayList<Object>();
        String SQL_GET_ALL_TABLES = "SELECT name FROM " + 
        "sqlite_master WHERE type='table' ORDER BY name"; 
        Cursor cursor = db.rawQuery(SQL_GET_ALL_TABLES, null);
        cursor.moveToFirst();
        if (!cursor.isAfterLast()) {
            do {
                tableList.add(cursor.getString(0));
            }
            while (cursor.moveToNext());
        }
        cursor.close();
        return tableList;
    }
+10
source

All Articles