Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get name and type from PRAGMA table_info()

In my android app, I need to get name and type from the result when I'm getting after execute the command PRAGMA table_info(table_name). How can I do this?

like image 566
Bishan Avatar asked Nov 16 '25 06:11

Bishan


1 Answers

It's as simple as that (db is your SQLiteDatabase object and tableName should be set to the correct table name inside your database):

String tableName = ""; // your table name
Cursor c = db.rawQuery("PRAGMA table_info(" + tableName + ")", null);
if (c.moveToFirst()) {
    do {
        System.out.println("name: " + c.getString(1) + " type: " + c.getString(2));
    } while (c.moveToNext());
}
c.close();
like image 78
andr Avatar answered Nov 17 '25 21:11

andr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!