Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a tables columns arraylist on Android?

I am after a code to get the available column names of a table in Android?

I looked around and didn't find anything.

like image 214
Pentium10 Avatar asked Mar 04 '10 20:03

Pentium10


2 Answers

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());
}
like image 73
Diego Torres Milano Avatar answered Oct 23 '22 05:10

Diego Torres Milano


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.

like image 44
Zul Avatar answered Oct 23 '22 06:10

Zul