현재 코드로 인해 애셋에서 데이터베이스를 업데이트 한 후 앱이 다운됩니다 (데이터베이스가 잘못되었습니다.). 어디서 문제가 있는지 알기 때문에 (테이블 스키마가 바뀌었기 때문에) 우선 SELECT를하고 * 임시 위치에 저장하여 새 데이터베이스에 덤프해야하지만 실제로 이것을 구현하는 방법을 모릅니다. 코드를 도와 주시겠습니까?SQlite 데이터베이스 onUpdate 충돌이 발생했습니다.
현재는 다음과 같습니다
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
try {
copyDatabase();
} catch (IOException e) {
throw new Error("Error copying database" + e.toString());
}
}
public void copyDatabase() throws IOException {
// Open your local db as the input stream
InputStream myinput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outfilename = DB_PATH + DB_NAME;
// Open the empty db as the output stream
OutputStream myoutput = new FileOutputStream(outfilename);
// transfer byte to inputfile to outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myinput.read(buffer)) > 0) {
myoutput.write(buffer, 0, length);
}
// Close the streams
myoutput.flush();
myoutput.close();
myinput.close();
}
은 BTW 앱 내가 잘 작동 모든게 다시 열 때, 첫 번째 응용 프로그램 실행에 충돌합니다. 사용자가 이전 버전을 사용하지 않고 최신 버전을 다운로드 한 경우에도 문제가 표시되지 않습니다.
로그 캣 :
06-28 17:11:54.456: E/SQLiteLog(25926): (11) database corruption at line 50987 of [00bb9c9ce4]
06-28 17:11:54.456: E/SQLiteLog(25926): (11) statement aborts at 4: [select count(*) from Numerical]
06-28 17:11:54.456: E/DefaultDatabaseErrorHandler(25926): Corruption reported by sqlite on database: /data/data/com.xxx.yyy/databases/database.db
06-28 17:11:54.456: E/DefaultDatabaseErrorHandler(25926): deleting the database file: /data/data/com.xxx.yyy/databases/database.db
06-28 17:11:54.456: E/AndroidRuntime(25926): FATAL EXCEPTION: main
06-28 17:11:54.456: E/AndroidRuntime(25926): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.yyy/com.xxx.yyy.PuzzleActivity}: android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed (code 11)
logcat을 게시 할 수 있습니까? – jkau
. 그것은 이미 거기 –