Ritik Kumar Agrahari Ritik Kumar Agrahari - 3 months ago 8
Android Question

Trouble in retrieving table names from Android sqlite database

i want to insert tables in android sqlite database and then want to show that table names in a listView but
after creating tables in database i am unable to retrieve table names from database , please help me out of this...
My code of retrieving table names is as follows-

public void updateBranchList()
{
//this method will open database
openDatabase();
String sql = "SELECT name FROM sqlite_temp_master WHERE type='table' ORDER BY name";
Cursor c = db.rawQuery(sql,null);
//branchList is an ArrayList<String>
branchList.clear();

if(c.moveToFirst())
while(!c.isAfterLast())
{
String s = c.getString(c.getColumnIndex("name"));
branchList.add(s);
c.moveToNext();
}
db.close();
}

public void openDatabase()
{
db = openOrCreateDatabase("studentinfo", Context.MODE_PRIVATE,null);
}

CL. CL.
Answer

The sqlite_temp_master table contains information about tables in the temporary database. For information about tables in the main database, you have to use sqlite_master instead.

Comments