如果我对数据库进行任何更改,例如在我的 android 应用程序中添加新列。如果我已经在手机上安装了它。当我在移动设备上重新安装/更新该应用程序时,它不会更新数据库更改。
我的数据库代码是:
package com.screenmagic.smsmagicmobileapp;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "Test";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(TAG, "onCreate OF DatabaseHandler");
db.execSQL("DROP TABLE IF EXISTS history");
String CREATE_SMS_HISTORY_TABLE = "CREATE TABLE history("+
"id INTEGER PRIMARY KEY AUTOINCREMENT, mobileNumber TEXT, smsText TEXT)";
Log.d("Insert: ", "Table create query:: "+ CREATE_SMS_HISTORY_TABLE);
db.execSQL(CREATE_SMS_HISTORY_TABLE);
Log.d("Insert: ", "Table created ..");
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS sms_history");
onCreate(db);
}
}