package com.feigdev.androidserialsql;

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

import java.util.Set;

/**
 * Created by ejohn on 9/2/13.
 */
public class GenericDBHelper extends SQLiteOpenHelper {
    private final DefineDB myDB;

    public GenericDBHelper(Context context, DefineDB myDB) {
        super(context, myDB.getDbName(), null, myDB.getVersion());
        this.myDB = myDB;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Set<String> tables = myDB.getTables();

        db.beginTransaction();
        for (String table : tables)
            db.execSQL(myDB.getTableDefenition(table));
        db.endTransaction();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        while (oldVersion < newVersion){
            oldVersion++;
            UpgradeRunnable r = myDB.getVersionUpgrade(oldVersion);

            if (null == r)
                continue;

            r.setDB(db);
            r.run();
        }
    }
}

@@ -159,16 +159,41 @@
 nHelper;
+%0Aimport android.util.Log;
 %0A%0Aimport
@@ -304,16 +304,73 @@
 elper %7B%0A
+    private static final String TAG = %22GenericDBHelper%22;%0A
     priv
@@ -730,16 +730,99 @@
  tables)
+ %7B%0A            Log.d(TAG, %22exec %22 + table + %22: %22 + myDB.getTableDefenition(table));
 %0A       
@@ -862,32 +862,42 @@
 nition(table));%0A
+        %7D%0A
         db.endTr
@@ -1005,24 +1005,24 @@
 wVersion) %7B%0A
-
         whil
@@ -1048,16 +1048,17 @@
 Version)
+ 
 %7B%0A      

add log