package dp.mendelu.roman.diplomkaapp42;


import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

/**
 * Pomocna databaze pro Reporty synchronizace dat.
 */
class DbHelp extends SQLiteOpenHelper {
    private static final String TAG = "DbHelp";
    //SQLiteDatabase db;

    public DbHelp(Context context) {
        super(context, Constants.DATABASE_NAME_REPORTS, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.i(TAG, "Creating database " + Constants.DATABASE_NAME_REPORTS +
                " table " + Constants.TABLE_NAME_REPORTS);
        db.execSQL("CREATE TABLE " + Constants.TABLE_NAME_REPORTS + " ( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                Constants.DB_TAG + " TEXT, " +
                Constants.LOG + " TEXT, " +
                Constants.TIME + " TEXT);");

        ContentValues cv=new ContentValues();

        cv.put(Constants.DB_TAG, TAG);
        cv.put(Constants.LOG, "Sync example");
        cv.put(Constants.TIME, "2015-12-21T23:14:48.265Z");

        db.insert(Constants.TABLE_NAME_REPORTS, Constants.DB_TAG, cv);

        Log.i(TAG, Constants.TABLE_NAME_REPORTS + " created");



    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i(TAG, "Upgrading database, which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS reports");
        onCreate(db);
    }
}