如何升级只读SQLite数据库SQLiteException:不能只读从版本X数据库升级为Y
我曾试图改变SQLiteDatabase.OPEN_READWRITE);
和getReadableDatabase();
结果还是一样。
当我想从版本1升级我的SQLite datatbase 2,我得到这个错误:
SQLiteException: Can't upgrade read-only database from version X to Y
在第1 verison我的应用程序中,我用这个代码:
private static final String DB_NAME = "this_the_database";
private final Context context;
private static final int DATABASE_VERSION = 1;
public DatabaseHelper(Context context) {
super(context, DB_NAME, null, DATABASE_VERSION);
this.context = context;
String path = context.getDatabasePath(DB_NAME).getAbsolutePath();
SQLiteDatabase db = null;
try {
db = SQLiteDatabase.openDatabase(path, null,
SQLiteDatabase.OPEN_READONLY);
} catch (SQLiteException e) { // DB not found
db = getReadableDatabase();
db.close();
// Copy DB from asset folder.
copyDatabase(path);
}
if (db != null) {
db.close();
}
}
当我决定以此来upgarde数据库,坠毁
@Override
public void onCreate(SQLiteDatabase db) {
new DatabaseHelper(context).getReadableDatabase();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DB_NAME);
onCreate(db);
}
编号:http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
请发布完整的例外日志 – Jack 2011-12-30 15:46:32