What do you think would be the right way to get all table names' from a database and add them to a list?
Right now got that far:
final ArrayList<String> dirArray = new ArrayList<String>();
SqlHelper sqlHelper = new SqlHelper(this, "TK.db", null, 1);
SQLiteDatabase DB = sqlHelper.getWritableDatabase();
Cursor c = DB.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
c.moveToFirst();
while (c.isAfterLast() == false) {
dirArray.add("n" + c.getColumnIndex("name"));
c.moveToNext();
}
c.close();
But it outputs some "android_metadata" instead of my table name's. So guess there's something wrong with the query.
Thanks!
The easiest way to find all tables in SQL is to query the INFORMATION_SCHEMA views. You do this by specifying the information schema, then the “tables” view. Here's an example. SELECT table_name, table_schema, table_type FROM information_schema.
PRAGMA table_info(table_name); will get you a list of all the column names.
Just did a quick test in the SQLite Manager plugin in FireFox with the SQLite db i'm working with and the query you're using does return the table names. Are you creating the tables correctly and have you tested the exist to your expectations?
To iterate through, do something like:
if (c.moveToFirst())
{
while ( !c.isAfterLast() ){
dirArray.add( c.getString( c.getColumnIndex("name")) );
c.moveToNext();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With