Android获取表格列表

时间:2011-01-13 15:27:13

标签: android database

有没有人知道SQL通过Android中的代码获取表名列表?我知道.tables是通过命令shell来完成的,但这不能通过代码完成。它与元数据有什么关系吗?

2 个答案:

答案 0 :(得分:10)

只需要做同样的事情。这似乎有效:

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;
    }

答案 1 :(得分:3)

知道了:

SELECT * FROM sqlite_master WHERE type='table'
相关问题