package org.plezervikt.dataexamples;

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

/**
 * Created by coelho on 2014.11.12..
 */
/*
    /data/data/org.plezervikt.dataexamples/databases/mydb.db
    sqlite3 nevű program kell hozzá
    https://play.google.com/store/apps/details?id=ptSoft.util.sqlite3forroot&hl=hu

*/
public class DatabaseHelper extends SQLiteOpenHelper {

    private final static String DB_NAME = "mydb.db";
    private final static int DB_VERSION = 2;

    public final static String TABLE_NAME = "my_table";

    public final static String COLUMN_ID = "_id";
    public final static String COLUMN_NAME = "name";
    public final static String COLUMN_HEIGHT = "height";

    private final static String CREATE_TABLE_MY = "CREATE TABLE " + TABLE_NAME + " (" +
            COLUMN_ID + " integer primary key autoincrement, " +
            COLUMN_NAME + " text not null, " +
            COLUMN_HEIGHT + " integer not null);";

    public DatabaseHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(CREATE_TABLE_MY);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
        if(oldVersion == 1 && newVersion == 2) {
            // milyen migrációs lépések kellenek, hogy az adatbázisunk épp maradjon
            // régi adatok kiolvasása, új tábla létrehozása, feltöltése
        }
    }
}
