package static final String LOC = “location”; private

package com.example.yasminanunez.timetable;/** * Created by yasminanunez on 22/11/2017. */import android.content.ContentValues;import android.content.Context;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteOpenHelper;import android.util.Log;import android.widget.EditText;public class DatabaseHelper extends SQLiteOpenHelper { private static final String TAG = “DatabaseHelper”; private static final String TABLE_NAME = “Table_Subjects”; private static final String ID = “ID”; private static final String NAME = “name”; private static final String START = “startTime”; private static final String END = “endTime”; private static final String LOC = “location”; private static final String TYPE = “classType”; private static final String TEACH = “teacher”; private static final String DAY = “day”; public DatabaseHelper(Context context) { super(context, TABLE_NAME, null, 1); } @Override public void onCreate(SQLiteDatabase db) { String createTable = “CREATE TABLE ” + TABLE_NAME + ” (ID INTEGER PRIMARY KEY AUTOINCREMENT, ” + NAME + ” TEXT, ” + START + ” TEXT, ” + END + ” TEXT, ” + LOC + ” TEXT, ” + TYPE + ” TEXT, ” + TEACH + ” TEXT, ” + DAY + ” TEXT );”; db.execSQL(createTable); } @Override public void onUpgrade(SQLiteDatabase db, int i, int i1) { db.execSQL(“DROP IF TABLE EXISTS ” + TABLE_NAME); onCreate(db); } public boolean addData(SchoolClass schoolclass){ SQLiteDatabase db = getWritableDatabase(); ContentValues values = new ContentValues(); values.put(NAME, schoolclass.getTitle()); values.put(START, schoolclass.getStartTime()); values.put(END, schoolclass.getEndTime()); values.put(LOC, schoolclass.getLocation()); values.put(TYPE, schoolclass.getClassType()); values.put(TEACH, schoolclass.getTeacher()); values.put(DAY, schoolclass.getDay()); long result = db.insert(TABLE_NAME, null, values); if(result == -1){ return false; } else{ return true; } } public Cursor getData(String item){ SQLiteDatabase db = this.getWritableDatabase(); String query = “SELECT rowid _id, ” + NAME + ” , ” + START + ” FROM ” + TABLE_NAME + ” WHERE ” + DAY + ” = ‘” + item + “‘”; Cursor data = db.rawQuery(query, null); return data; } public Cursor getItemID(String name, String day){ SQLiteDatabase db = this.getWritableDatabase(); String query = “SELECT ” + LOC + ” , ” + TYPE + ” , ” + TEACH + ” FROM ” + TABLE_NAME + ” WHERE ” + NAME + ” = ‘” + name + “‘”+ ” AND ” + DAY + ” = ‘” + day + “‘”; Cursor data = db.rawQuery(query, null); return data; } public Cursor getDetails(String name, String day){ SQLiteDatabase db = this.getWritableDatabase(); String query = “SELECT ” + START + ” , ” + END + ” , ” + LOC + ” , ” + TYPE + ” , ” + TEACH + ” FROM ” + TABLE_NAME + ” WHERE ” + NAME + ” = ‘” + name + “‘”+ ” AND ” + DAY + ” = ‘” + day + “‘”; Cursor data = db.rawQuery(query, null); return data; } public void updateData(String newName, String newST, String newET, String newLoc, String newCT, String newTeach, String weekDay, String oldName){ SQLiteDatabase db = getWritableDatabase(); String query = “UPDATE ” + TABLE_NAME + ” SET ” + NAME + ” = ‘” + newName + “‘” + ” , ” + START + ” = ‘” + newST + “‘” + ” , ” + END + ” = ‘” + newET + “‘” + ” , ” + LOC + ” = ‘” + newLoc + “‘” + ” , ” + TYPE + ” = ‘” + newCT + “‘” + ” , ” + TEACH + ” = ‘” + newTeach + “‘” + ” WHERE ” + NAME + ” = ‘” + oldName + “‘” + ” AND ” + DAY + ” = ‘” + weekDay + “‘;”; db.execSQL(query); } public void deleteData(String weekDay, String oldName){ SQLiteDatabase db = getWritableDatabase(); String query = “DELETE FROM ” + TABLE_NAME + ” WHERE ” + NAME + ” = ‘” + oldName + “‘” + ” AND ” + DAY + ” = ‘” + weekDay + “‘;”; db.execSQL(query); }}

x

Hi!
I'm James!

Would you like to get a custom essay? How about receiving a customized one?

Check it out