java - How to get all table names in android sqlite database? -
i have try code
cursor c=db.rawquery("select name sqlite_master type = 'table'",null); c.movetofirst(); while(!c.isafterlast()){ toast.maketext(activityname.this, "table name=> "+c.getstring(0), toast.length_long).show(); }
but throws error "android.database.sqlite.sqliteexception: no such table: sqlite_master(code 1):,while compiling: select name sqlite_master type='table'"
how fetch table name? me
thanks in advance..
checked, tested , functioning. try code:
cursor c = db.rawquery("select name sqlite_master type='table'", null); if (c.movetofirst()) { while ( !c.isafterlast() ) { toast.maketext(activityname.this, "table name=> "+c.getstring(0), toast.length_long).show(); c.movetonext(); } }
i assuming, @ point down line, grab list of table names display in perhaps listview
or something. not show toast.
untested code. came @ top of mind. test before using in production app. ;-)
in event, consider following changes code posted above:
arraylist<string> arrtblnames = new arraylist<string>(); cursor c = db.rawquery("select name sqlite_master type='table'", null); if (c.movetofirst()) { while ( !c.isafterlast() ) { arrtblnames.add( c.getstring( c.getcolumnindex("name")) ); c.movetonext(); } }
Comments
Post a Comment