如何获得所有表present的姓名,在Android的精简版SQL数据库 [英] How to get the names of all tables present in a database in Android SQL lite
本文介绍了如何获得所有表present的姓名,在Android的精简版SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不能找到一个办法让/转储表名从在android系统数据库中的文本视图。我知道:查询
I cant find a way to get/dump table names in a text view from a database in android. I know about:querying
SELECT *
FROM sqlite_master
上面的语句导致指向所有数据库/视图/表的元数据的指针。但我怎么能取我创建的所有表的名字在我的数据库?
The above statement results a cursor pointing the metadata about all databases/view/tables. But how can I fetch the names of all the tables I created, in my database?
推荐答案
如果要检索数组中的信息(或者您可以通过字符串遍历的结构),你可以像一个方法:
If you want to retrieve the info in an array (or any structure which you can iterate through strings), you can make a method like:
public String[] getDBNames(){
String[] result;
try {
StringBuilder sb = new StringBuilder();
sb.append("SELECT name FROM sqlite_master ");
sb.append("WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%' ");
sb.append("UNION ALL ");
sb.append("SELECT name FROM sqlite_temp_master ");
sb.append("WHERE type IN ('table','view') ");
sb.append("ORDER BY 1");
Cursor c = _db.rawQuery(sb.toString(), null);
c.moveToFirst();
result = new String[c.getCount()];
int i = 0;
while (c.moveToNext()) {
result[i]= c.getString(c.getColumnIndex("name"));
i++;
}
c.close();
}
catch(SQLiteException e){
Log.e("OOPS", e);
}
return result;
}
这篇关于如何获得所有表present的姓名,在Android的精简版SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文