Android Sqlite Show Tables
Is it possible to query the list of tables in a database into a Cursor? I don't know how to implement the show tables method in android. One way is to store all tables in a 'collec
Solution 1:
I found the solution. In the SQLiteOpenHelper class:
publicCursorshowAllTables(){
String mySql = " SELECT name FROM sqlite_master " + " WHERE type='table' "
+ " AND name LIKE 'PR_%' ";
return ourDatabase.rawQuery(mySql, null);
}
In the activity:
Cursor c = info.showAllTables();
if (c.moveToFirst())
{
do{
todoItems.add(c.getString(0));
}while (c.moveToNext());
}
if (todoItems.size() >= 0)
{
for (int i=0; i<todoItems.size(); i++)
{
Log.d("TODOItems(" + i + ")", todoItems.get(i) + "");
}
}
Solution 2:
In SQLite you should be able to query SQLITE_MASTER. Not tested this on Android though. See http://sqlite.org/faq.html#q7
Post a Comment for "Android Sqlite Show Tables"