例外:Androidでは、これはSQLiteDatabaseヘルパーを設定する正しい方法ですか?
CREATE TABLE android_metadata failed
Failed to setLocale() when constructing, closing the database
android.database.sqlite.SQLiteException: database is locked
私のアプリが正常に動作してONUPGRADE()が呼び出されたときを除いて、何デシベルの問題を持っていません。
onUpgradeが自動的に呼び出されると、以下のCarManagerクラスを使用してアップグレードに必要なデータ操作を実行しようとします。これは、dbがロックされているため失敗します。
行うには、通常のものでなければなりませんように、これはと思われるので、(2つのクラスが、ヘルパーとテーブルマネージャに従ってください)私が正しく、次のコードを構造化されてはならないようだ。
public class DbHelper extends SQLiteOpenHelper {
private Context context;
//Required constructor
public DbAdapter(Context context)
{
super(context, "my_db_name", null, NEWER_DB_VERSION);
this.context = context;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
overrideDB = db;
CarManager.migrateDataForOnUpgrade(context);
}
}
public class CarManager {
DbHelper dbHelper;
public CarManager(Context context)
{
dbHelper = new DbHelper(context);
}
public void addCar(String make, String model)
{
ContentValues contentValues = new ContentValues();
contentValues.put("make", make);
contentValues.put("model", model);
SQLiteDatabase db = dbHelper.getWritableDatabase();
db.insert("car", null, contentValues);
db.close();
}
public static void migrateDataForOnUpgrade()
{
//Code here that migrates data when onUpgrade() is called
//Db lock happens here
}
}
どれでもアイデア? テーブル管理者(例:dao)はこれとは異なる方法で設定しますか?
編集:私はGoogleのチーム@ Android開発者の時間に話をしました。彼らはonUpgrade3が決して構造変化(変更)のようなことをすることはないと言いました。そう、はい、今のところ多くの場合に使用されなければならないハックがあるようです。
好奇心のために、OrmLite(http://ormlite.com/)はDAOクラスを設定する良い方法です。 – jcxavier
例外を投稿する – Jack
例外は何ですか? – drulabs