I am after a code to get the available column names of a table in Android?
I looked around and didn't find anything.
This is a simpler way:
Cursor ti = db.rawQuery("PRAGMA table_info(mytable)", null);
if ( ti.moveToFirst() ) {
do {
System.out.println("col: " + ti.getString(1));
} while (ti.moveToNext());
}
The simplest way I've implemented.
Cursor cursor = db.rawQuery("SELECT * FROM " + tableName + " LIMIT 1", null);
String[] colNames = cursor.getColumnNames();
Any better suggestion are welcome.
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