package com.mick88.dittimetable;

import java.util.List;

import android.content.Context;
import android.util.Log;

import com.michaldabski.msqlite.MSQLiteOpenHelper;
import com.mick88.dittimetable.timetable.Timetable;

public class DatabaseHelper extends MSQLiteOpenHelper
{
	private static final String name = "timetables.db";
	private static final int version = 1;
	private static final String TAG = "SQLite";
	
	public DatabaseHelper(Context context) {
		super(context, name, null, version, new Class<?>[]{
				Timetable.class,
		});
	}
	
	public Timetable getTimetable(String course, int year, String weeks)
	{
		List<Timetable> timetables = select(Timetable.class, "course=? AND year=? and weekRange=?", 
				new String[]{course, String.valueOf(year), weeks}, 
				null, "1");
		if (timetables.isEmpty()) return null;
		Log.d(TAG, "Timetable loaded: "+timetables.get(0).describe());
		return timetables.get(0);
	}
	
	public void saveTimetable(Timetable timetable)
	{
		replace(timetable);
		Log.d(TAG, "Timetable saved: "+timetable.describe());
	}
}

@@ -1047,10 +1047,167 @@
 ());%0A%09%7D%0A
+%09%0A%09/**%0A%09 * returns all timetables saved in database%0A%09 * @return%0A%09 */%0A%09public List%3CTimetable%3E getSavedTimetables()%0A%09%7B%0A%09%09return selectAll(Timetable.class);%0A%09%7D%0A
 %7D%0A

Add method to get all saved timetables