其实我不使用ORMLite但是我不想集成它,但是如何管理版本控制,例如我这样做:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < 4) {
db.execSQL("ALTER TABLE " + "demandes" + " RENAME TO demandes2");
db.execSQL("CREATE TABLE " + "demandes" + "(" + "id" + " INTEGER PRIMARY KEY," + "xmlSendLead" + " TEXT," + "statutEnvoieSendLead" + " INTEGER," + "dateEnvoieSendLead" + " DATETIME," + "contactWebId" + " INTEGER," + "xmlSimulation" + " TEXT," + "statutEnvoieSimulation" + " INTEGER," + "dateEnvoieSimulation" + " DATETIME" + ")");
db.execSQL("INSERT INTO " + "demandes" + " (" + "id" + "," + "xmlSendLead" + "," + "statutEnvoieSendLead" + "," + "dateEnvoieSendLead" + ")" + " SELECT id, xml, statutEnvoie, dateEnvoie" + " FROM demandes2;");
db.execSQL("DROP TABLE demandes2");
System.out.println("v4 parsed");
}
if (oldVersion < 5) {
db.execSQL("CREATE TABLE " + "leads" + "(" + "id" + " INTEGER PRIMARY KEY," + "xmlSendLead" + " TEXT," + "statutSendLead" + " INTEGER," + "dateSendLead" + " DATETIME," + "contactWebId" + " INTEGER," + "xmlSimulation" + " TEXT," + "statutSendSimulation" + " INTEGER," + "dateSendSimulation" + " DATETIME" + ")");
db.execSQL("INSERT INTO " + "leads" + " (" + "id" + "," + "xmlSendLead" + "," + "statutSendLead" + "," + "dateSendLead" + "contactWebId" + "," + "xmlSimulation" + "," + "statutSendSimulation" + "," + "dateSendSimulation" + ")" + " SELECT id, xml, statutEnvoie, dateEnvoie" + " FROM demandes2;");
db.execSQL("CREATE TABLE " + "leads" + "(" + "id" + " INTEGER PRIMARY KEY," + "prepaymentPenaltyPercentage" + " REAL," + "notaryFeeGrid" + " INTEGER," + "immoRatePercentage" + " REAL," + "immoMinMonthly" + " INTEGER," + "immoMaxMonthly" + " INTEGER," + "fileFeePercentage" + " REAL," + "date" + " DATETIME," + "consoRatePercentage" + " REAL," + "consoMinMonthly" + " INTEGER," + "consoMaxMonthly" + " INTEGER," + "bankFeePercentage" + " REAL)");
}
}
请不要关心字符串连接,如何重命名表/列或在两个表之间插入数据?