面白い。そのため、このonDowngrade(...)
メソッドはAPI11で追加されました。ORMLiteにサポートを追加するだけでは不十分です。残念ながら、onDowngrade
これは、のと同じ独自のメソッドを作成する必要があることを意味onUpgrade(...)
しますOrmLiteSqliteOpenHelper
。次のようなもの:
public abstract void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion,
int newVersion) {
// your code goes here
}
public final void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
ConnectionSource cs = getConnectionSource();
/*
* The method is called by Android database helper's get-database calls when Android detects that we need to
* create or update the database. So we have to use the database argument and save a connection to it on the
* AndroidConnectionSource, otherwise it will go recursive if the subclass calls getConnectionSource().
*/
DatabaseConnection conn = cs.getSpecialConnection();
boolean clearSpecial = false;
if (conn == null) {
conn = new AndroidDatabaseConnection(db, true);
try {
cs.saveSpecialConnection(conn);
clearSpecial = true;
} catch (SQLException e) {
throw new IllegalStateException("Could not save special connection", e);
}
}
try {
onDowngrade(db, cs, oldVersion, newVersion);
} finally {
if (clearSpecial) {
cs.clearSpecialConnection(conn);
}
}
}
このonDowngrade(...)
方法の詳細については、以下を参照してください。
public void onDowngrade (SQLiteDatabase db, int oldVersion, int newVersion);
javadocsから引用するには:
データベースをダウングレードする必要がある場合に呼び出されます。これはonUpgrade(SQLiteDatabase、int、int)メソッドと厳密に似ていますが、現在のバージョンが要求されたバージョンよりも新しい場合は常に呼び出されます。ただし、この方法は抽象的ではないため、お客様が実装する必要はありません。オーバーライドされない場合、デフォルトの実装はダウングレードを拒否し、SQLiteExceptionをスローします
以下も参照してください。
データベースをバージョン2から1にダウングレードできません