package dp.mendelu.roman.diplomkaapp42;


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

/**
 * Pomocna trida databaze pro ukladani informaci aplikace
 */
public class DatabaseHelper extends SQLiteOpenHelper {
    private final String TAG = "DatabaseHelper";
    //SQLiteDatabase db;


    public DatabaseHelper(Context context) {
        super(context, Constants.DATABASE_NAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.i(TAG, "Creating database " + Constants.DATABASE_NAME +
                   " table " +  Constants.TABLE_NAME );
        db.execSQL("CREATE TABLE " + Constants.TABLE_NAME + " ( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                Constants.UPDATED_AT + " TEXT, " +
                Constants.CREATED_AT + " TEXT, " +
                Constants.DOC_ID + " TEXT, " +
                Constants.JSON + " TEXT, " +
                Constants.LATITUDE + " REAL, " +
                Constants.LONGITUDE + " REAL);");

        /**
         * Ukazkova 1.id jsonu do lokalu
         *
        ContentValues cv=new ContentValues();

        cv.put(Constants.UPDATED_AT, "2015-12-22T12:20:14.719Z");
        cv.put(Constants.CREATED_AT, "2015-12-21T23:14:48.265Z");
        cv.put(Constants.DOC_ID, "567887e8e4b0de2ac1c54211");
        cv.put(Constants.LONGITUDE, 81.752);
        cv.put(Constants.LATITUDE, -74.855);
        cv.put(Constants.JSON, "{123545}");
        db.insert(Constants.TABLE_NAME, Constants.JSON, cv);*/

        Log.i(TAG, Constants.DATABASE_NAME + " 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 geometry");
        onCreate(db);
    }
}
