package com.example.preferences02;

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

public class DBHelper extends SQLiteOpenHelper {
	//define all the constants
    static String DATABASE_NAME="fstmdirektori";
    public static final String TABLE_NAME="staflist";
    //these are the lit of fields in the table
    public static final String STAFID="stafid";
    public static final String NAMA="namapenuh";
    public static final String JBT="jabatan";
    public static final String TELEFON="telefon";
    public static final String EMEL="emel";
    
    public DBHelper(Context context) {
    	//create the database
        super(context, DATABASE_NAME, null, 1);
       
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
    	//create the table
        String CREATE_TABLE="CREATE TABLE "+TABLE_NAME+" ("+STAFID+" INTEGER PRIMARY KEY, "+NAMA+" TEXT, "+JBT+" TEXT, "+TELEFON+" TEXT,"+EMEL+" TEXT)";
        db.execSQL(CREATE_TABLE);
        //populate dummy data
        db.execSQL("INSERT INTO staflist (stafid, namapenuh, jabatan, telefon, emel) VALUES('1', 'Khirulnizam Abd Rahman', 'JSK','0129034614', 'khirulnizam@gmail.com');");
        db.execSQL("INSERT INTO staflist (stafid, namapenuh, jabatan, telefon, emel) VALUES('2', 'Noorazli Masrop', 'JMM','01297324378', 'noorazli@kuis.edu.my');");
        db.execSQL("INSERT INTO staflist (stafid, namapenuh, jabatan, telefon, emel) VALUES('3', 'Muhammad Luqman', 'JSK','0112345423', 'luke@kuis.edu.my');");
        db.execSQL("INSERT INTO staflist (stafid, namapenuh, jabatan, telefon, emel) VALUES('4', 'Hasnuddin Hasnol', 'JMM','0112314233', 'din@kuis.edu.my');");
        db.execSQL("INSERT INTO staflist (stafid, namapenuh, jabatan, telefon, emel) VALUES('5', 'Muizz Salleh', 'JMM','0129787867', 'muizz@kuis.edu.my');");
        db.execSQL("INSERT INTO staflist (stafid, namapenuh, jabatan, telefon, emel) VALUES('6', 'Muna Sabah', 'JSK','0134234343', 'moon@kuis.edu.my');");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    	//onUpgrade remove the existing table, and recreate and populate new data
        db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
        onCreate(db);

    }

}


