package com.wingjay.jianshi.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by wingjay on 9/30/15.
 */
public class DbOpenHepler extends SQLiteOpenHelper {

    public final static int DB_VAERION = 2;
    public final static String DB_NAME = "jianshi";

    private final String CREATE_TABLE_DIARY_1 = "create table if not exists diary " +
            "(id integer primary key autoincrement," +
            "device_id string not null," +
            "title string not null," +
            "content string not null," +
            "created_time long not null," +
            "modified_time long )";

    private final String ADD_COLUMN_DELETE_IN_DIARY_2 = "alter table diary " +
            "add column deleted integer default 0";

    public DbOpenHepler(Context context, String name, int version) {
        super(context, name, null, version);
    }

    public DbOpenHepler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_DIARY_1);
        db.execSQL(ADD_COLUMN_DELETE_IN_DIARY_2);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (newVersion == 2) {
            db.execSQL(ADD_COLUMN_DELETE_IN_DIARY_2);
        }
    }
}

@@ -292,17 +292,17 @@
 ERION = 
-2
+3
 ;%0A    pu
@@ -352,32 +352,39 @@
 %22;%0A%0A    private 
+static 
 final String CRE
@@ -712,16 +712,23 @@
 private 
+static 
 final St
@@ -835,18 +835,467 @@
 efault 0
-%22;
+ after content%22;%0A%0A    private static final String ADD_DIARY_ID_IN_DIARY_3 = %22alter table diary%22 +%0A        %22 add column diary_id integer after id; %22 +%0A        %22 alter table diary add column time_removed long after modified_time%22;%0A%0A    private static final String%5B%5D sqlArray = new String%5B3%5D;%0A    static %7B%0A        sqlArray%5B0%5D = CREATE_TABLE_DIARY_1;%0A        sqlArray%5B1%5D = ADD_COLUMN_DELETE_IN_DIARY_2;%0A        sqlArray%5B2%5D = ADD_DIARY_ID_IN_DIARY_3;%0A    %7D
 %0A%0A    pu
@@ -1719,24 +1719,69 @@
 N_DIARY_2);%0A
+        db.execSQL(ADD_DIARY_ID_IN_DIARY_3);%0A
     %7D%0A%0A    @
@@ -1880,12 +1880,25 @@
     
-if (
+for (int i=1; i%3C=
 newV
@@ -1907,13 +1907,13 @@
 sion
- == 2
+; i++
 ) %7B%0A
@@ -1939,36 +1939,21 @@
 SQL(
-ADD_COLUMN_DELETE_IN_DIARY_2
+sqlArray%5Bi-1%5D
 );%0A 

modify local db