0
ORMLiteを使用しています。新しいバージョンをリリースします。 これのために私はこのようなDBアップグレードスクリプト(json)を持っています。DBアップグレード中にORMLiteに存在しない場合、新しい列を作成する方法
{
"version": 9,
"ddlQueries": [
{
"queryDescription": "add a new column column name in tablename table",
"commandType": "ALTER",
"table": "table name",
"column": {
"name": "column name",
"type": "BLOB"
}
},
{
"queryDescription": "Create a new column column name in table name table",
"commandType": "ALTER",
"table": "table name",
"column": {
"name": "column name",
"type": "TEXT"
}
}
]
}
このような私のonUpgradeメソッド。
public void onUpgrade(Object db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try {
while(++oldVersion<=newVersion) {
AssetManager assetManager = context.getAssets();
InputStream inputStream = assetManager.open(MIGRATION_SCRIPT_PATH + "version-" + oldVersion + ".json");
List<String> queries = new QueryBuilder().loadQueries(new InputStreamReader(inputStream));
inputStream.close();
for (String sql : queries) {
executeSQL(db, sql);
}
postUpgrade(db, connectionSource, oldVersion);
}
} catch (IOException e) {
Log.e(AccountsDBHelper.class.getName(), "exception during onUpgrade", e);
//Below exception must be thrown to rollback changes.
throw new RuntimeException(e);
}
}
は今、私はその後、存在しない場合は唯一の私は、新しい列を作成したい、列が既に存在するかどうかを確認したいそうでない場合は無視します。
どうすればいいですか?
ありがとうございました。