Эх сурвалжийг харах

upgrade:进出记录,数据格式不对引引起的奔溃问题

xwh 1 долоо хоног өмнө
parent
commit
2ccb4904d8

+ 7 - 4
app/src/main/java/com/hanghui/senic/dao/RecordSaveHelper.java

@@ -8,9 +8,9 @@ import android.database.sqlite.SQLiteOpenHelper;
  * 创建数据库保存失败的进出记录
  */
 public class RecordSaveHelper extends SQLiteOpenHelper {
-    private static Integer version = 1;
+    private static Integer version = 2;
     private static String name = "recordSave.db";
-
+    private final String TABLENAME = "recordSave";
     public RecordSaveHelper(Context context) {
         super(context, name, null, version);
     }
@@ -22,8 +22,11 @@ public class RecordSaveHelper extends SQLiteOpenHelper {
     }
 
     @Override
-    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
-
+    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
+        if (newVersion > oldVersion) {
+            sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLENAME);
+            onCreate(sqLiteDatabase);
+        }
     }
 
     @Override