Saya telah merilis aplikasi (Waktu Dunia) dengan database awal. Sekarang saya ingin memperbarui aplikasi dengan peningkatan basis data.
Saya telah memasukkan kode pemutakhiran di OnUpgrade() dan memeriksa Versi baru. Tapi itu tidak dipanggil dalam pengujian lokal saya...
Jadi saya memasukkan pernyataan debug untuk mendapatkan versi database dan hasilnya nol.
Adakah yang tahu mengapa itu tidak diversi?
Berikut ini adalah kode untuk menyalin database dari folder Aset saya ...
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
Berikut ini adalah konstruktor saya, OnCreate() & OnUpgrade()
public DatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
this.myContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if(oldVersion == 1 && newVersion == 2){
String sql = "update statement...."; // i have a correct update statement here
db.execSQL(sql);
}
}
--
Mahesh
http://android.maheshdixit.com
SQLiteOpenHelper
Anda padaonCreate()
danonUpgrade()
jika Anda berharap mendapatkan bantuan dengan implementasiSQLiteOpenHelper
Anda padaonCreate()
danonUpgrade()
- person CommonsWare   schedule 06.06.2010