有人知道在Android代码中获取表名列表的SQL语句吗?我知道通过命令行使用.tables
可以实现,但是在代码中无法使用。这与元数据等是否有关?
我也遇到了同样的问题。这似乎有效:
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;
}
Got it:
SELECT * FROM sqlite_master WHERE type='table'