我正在使用下面的代码从资产中导入预填充(ORMLite)数据库。
除了 Galaxy Note 10.1 之外,这在多个设备上都可以正常工作。操作完成后关闭数据库时出现异常:
“错误代码 = 11,味精 = 行中的数据库损坏 ....”
当我从设备下载数据库并在 SqliteBrowser 中打开它时,一切似乎都很好。有任何想法吗 ?
public class MySQLiteOpenHelper extends SQLiteOpenHelper {
// {....}
public void importDB() {
InputStream is = context.getAssets().open("DBName.db");
try {
close();
FileOutputStream os = new FileOutputStream(new File(Environment.getDataDirectory(), dbPath));
try {
byte[] buffer = new byte[4096];
for (int n; (n = is.read(buffer)) != -1;) {
os.write(buffer, 0, n);
}
} finally {
os.close();
}
} finally {
is.close();
}
getWritableDatabase().close();
}
错误:
I/SqliteDatabaseCpp(684): sqlite returned: error code = 11, msg = database corruption at line 48171 of [ed759d5a9e], db=/data/data/app_name/databases/DBName_db
I/SqliteDatabaseCpp(684): sqlite returned: error code = 11, msg = database disk image is malformed, db=/data/data/app_name/databases/DBName_db
E/SqliteDatabaseCpp(684): sqlite3_exec - Failed to set synchronous mode = 1(Normal)
I/SqliteDatabaseCpp(684): sqlite returned: error code = 11, msg = database corruption at line 48171 of [ed759d5a9e], db=/data/data/app_name/databases/DBName_db
I/SqliteDatabaseCpp(684): sqlite returned: error code = 11, msg = database disk image is malformed, db=/data/data/app_name/databases/DBName_db
E/SqliteDatabaseCpp(684): CREATE TABLE android_metadata failed
E/DefaultDatabaseErrorHandler(684): Corruption reported by sqlite on database: /data/data/app.name/databases/DBName.db
E/DefaultDatabaseErrorHandler(684): deleting the database file: /data/data/app.name/databases/DBName.db