我正在使用Android和ORMLite。我是新手,我升級數據庫到版本2.我有類「自動」,需要刪除列別名。在ORMLite中更改架構時刪除列
@DatabaseTable(tableName = "Auto")
public class Auto {
public static final String ALIAS = "alias";
public static final String PLACA = "placa";
@DatabaseField(generatedId = true, columnName = "ID")
private int id;
@DatabaseField(canBeNull = false, columnName = ALIAS)
private String alias;
@DatabaseField(canBeNull = false, columnName = PLACA)
public Auto()
{
//ORMLite needs a no-arg constructor
}
public Auto(String alias, String placa) {
this.alias = alias;
this.placa = placa;
}
…..
…..
}
我改變類自動爲...
@DatabaseTable(tableName = "Auto")
public class Auto {
public static final String PLACA = "placa";
@DatabaseField(generatedId = true, columnName = "ID")
private int id;
@DatabaseField(canBeNull = false, columnName = PLACA)
public Auto()
{
//ORMLite needs a no-arg constructor
}
public Auto(String alias, String placa) { this.placa = placa;
}
…..
…..
}
我需要知道,如果ORMLite在執行「onUpgradeMethod」還是我不得不手動做這樣的自動刪除列別名。
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
if(oldVersion == 1) {
try {
Dao dao;
dao = getAutoDao();
dao.executeRaw("ALTER TABLE `Auto` DROP COLUMN alias;");
} catch (SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Error ", e);
}
}
}