SELECT * FROM sqlite_master WHERE type ='table'在Android Pie中以sqlite返回元数据表

时间:2019-01-17 07:28:09

标签: android sqlite

我正在使用Google Play Android API 28(Android PIE)模拟器。我的代码是

Cursor cursor_names = db.rawQuery("SELECT * FROM sqlite_master WHERE type='table'", null);
Log.e("Cursor Count",cursor_names.getCount()+"");
cursor_names.moveToFirst();
while (!cursor_names.isAfterLast()) {
      String name=cursor_names.getString(cursor_names.getColumnIndex("tbl_name"));
      Log.e("Table Name",name);
      cursor_names.moveToNext();
 }

Logcat是

E/Cursor Count: 1
E/Table Name: android_metadata

在以前的android版本上,我得到了表列表,每个查询都将执行。 android 9有什么问题?

1 个答案:

答案 0 :(得分:0)

您可以尝试

if (cursor_names.moveToFirst()) {
    while ( !cursor_names.isAfterLast() ) {
        String name=cursor_names.getString(cursor_names.getColumnIndex("tbl_name"));
        cursor_names.moveToNext();
    }
}

备用

 // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            // Your work
        } while (cursor.moveToNext());
    }