은 옵션 3의 sligthly 더 나은 버전 (alerdy를 보여주고 데이터베이스와 엔티티의 수를 언제 어떻게 변경하는지)를 보여 주며 모든 데이터베이스와 엔티티를 초기화하는 클래스를 만들었습니다 (DaoMaster.DevOpenHelper, SQLiteDatabase 및 entityNameDao), 거기, 나는 데이터베이스 이름을 얻고 모든 엔티티의 목록을 만들고 그것을 활동에 전달하고 거기에서 Dao로 엔티티의 데이터 목록을 얻는다. 내가 그것을 만들고 싶지는 않지만 적어도 업데이트하는 것은 엉망이 아닙니다.
편집 : 오케이. 잠시 후 나는 모든 데이터베이스를 제외한 모든 데이터를 Sqlite로 가져올 수 있다는 것을 알게되었습니다. 테이블이나 단체의 경우 당신은 당신이 먼저 Cursor.getColumnNames();
와 부가 요소를 가져온 다음 여기에 getColumnIndex();
으로 그들을 얻을 수있는 데이터를 얻기 위해, 각 테이블을 조회 할 수있는 모든 테이블 이름으로 지금 SELECT name FROM sqlite_master WHERE type='table'
를 조회 할 수있는 것은 약간의 예를
ArrayList<String> arrTblNames = new ArrayList<>();
List<List<String>> data = new ArrayList<>();
Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
if (c.moveToFirst()) {
while (!c.isAfterLast()) {
arrTblNames.add(c.getString(c.getColumnIndex("name")));
c.moveToNext();
}
}
for(int i=0; i<=arrTblNames.size()-1;i++){
Cursor dbCursor = db.query(arrTblNames.get(i), null, null, null, null, null, null);
String[] columnNames = dbCursor.getColumnNames();
Cursor c2 = db.query(arrTblNames.get(i),columnNames,null,null,null,null,null);
if (c2.moveToFirst()) {
while (!c2.isAfterLast()) {
data.add(new ArrayList<String>());
for(int j=0; j<=columnNames.length-1;j++){
data.get(i).add(c2.getString(c2.getColumnIndex(columnNames[j])));
}
c2.moveToNext();
}
}
}
입니다