package com.cpm.lorealbaautomation.bulkInsert;

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

public class DBHelper extends SQLiteOpenHelper {
    //if you change the schema of the database, you must increment this number
    private static final int DATABASE_VERSION=1;
    static final String DATABASE_NAME="mydatabase.db";
    private static DBHelper mInstance=null;
    public static DBHelper getInstance(Context ctx){
        if(mInstance==null){
            mInstance= new DBHelper(ctx.getApplicationContext());
        }
        return mInstance;
    }

    public DBHelper(Context context){
        super(context,DATABASE_NAME,null,DATABASE_VERSION);
    }

    public int GetDatabase_Version() {
        return DATABASE_VERSION;
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase){
//Create the table users
        final String SQL_CREATE_TABLE_USERS="CREATE TABLE "+ DBContract.UserEntry.TABLE_NAME+ " ("+
                DBContract.UserEntry._ID+" INTEGER PRIMARY KEY, "+
                DBContract.UserEntry.COLUMN_Name+" TEXT , "+
                DBContract.UserEntry.COLUMN_Password+" TEXT "+
                " ); ";

        sqLiteDatabase.execSQL(SQL_CREATE_TABLE_USERS);

    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
        sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + DBContract.UserEntry.TABLE_NAME);
    }

}

