android sqlite查詢數據表的字段與相關屬性

在sqlite中如果想查詢某個表的所有字段與屬性。
輸入語句:

//user是表名
pragma table_info(user);

android 相關代碼,測試可行:

MysqliteHelper mysqliteHelper = new MysqliteHelper(context);
        SQLiteDatabase db = mysqliteHelper.getReadableDatabase();
        Cursor cursor = db.rawQuery("pragma table_info( org_user )", null);
        while (cursor.moveToNext()) {
            String[] columnNames = cursor.getColumnNames();
            for(String name:columnNames){
                Log.w("tag", "name=="+name+"==value=="+cursor.getString(cursor.getColumnIndex(name)));
            }
        }
        cursor.close();
        db.close();

在sqliteexpert中的效果:
這裡寫圖片描述

You May Also Like