Android Open Source - BsuirSchedule D B Helper






From Project

Back to project page BsuirSchedule.

License

The source code is released under:

Copyright 2012 Andrei Senchuk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softwar...

If you think the Android project BsuirSchedule listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.taviscaron.bsuirschedule.storage;
/*www .j av  a 2 s  . c  om*/
import net.taviscaron.bsuirschedule.model.Lesson;
import net.taviscaron.bsuirschedule.model.Schedule;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import android.util.Log;

public class DBHelper extends SQLiteOpenHelper {
    private static final String TAG = "DBHelper";
    private static final int DB_VERSION = 1;
    private static final String DB_NAME = "schedules";
    
    public DBHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }
    
    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.i(TAG, "create the database version " + DB_VERSION);
        
        String schedTableCreate = String.format(
                "create table %s (%s integer primary key, %s text, %s integer, %s integer, %s integer, %s text, %s text, %s integer);", Schedule.TABLE_NAME,
                BaseColumns._ID, Schedule.FACULTY_ATTR, Schedule.YEAR_ATTR, Schedule.COURSE_ATTR, Schedule.TERM_ATTR, Schedule.STREAM_ATTR,
                Schedule.GROUP_ATTR, Schedule.UPDATE_DATE_ATTR);
        db.execSQL(schedTableCreate);
        
        String lessonTableCreate = String.format(
                "create table %s (%s integer primary key, %s integer, %s integer, %s integer, %s integer, %s integer, %s text, %s text, %s text, %s integer);",
                Lesson.TABLE_NAME, BaseColumns._ID, Lesson.SCHEDULE_ATTR, Lesson.DAY_ATTR, Lesson.TIME_ATTR, Lesson.WEEKS_ATTR, Lesson.SUBGROUP_ATTR,
                Lesson.AUDITORIUM_ATTR, Lesson.TEACHER_ATTR, Lesson.SUBJ_ATTR, Lesson.TYPE_ATTR);
        db.execSQL(lessonTableCreate);
    }
    
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i(TAG, "upgrade the database storage from " + oldVersion + " to " + newVersion);
        db.execSQL(String.format("drop table %s;", Schedule.TABLE_NAME));
        db.execSQL(String.format("drop table %s;", Lesson.TABLE_NAME));
    }
}




Java Source Code List

net.taviscaron.bsuirschedule.activity.LessonsListActivity.java
net.taviscaron.bsuirschedule.activity.MainActivity.java
net.taviscaron.bsuirschedule.activity.ManageSchedulesActivity.java
net.taviscaron.bsuirschedule.activity.SettingsActivity.java
net.taviscaron.bsuirschedule.adapter.LessonsListAdapter.java
net.taviscaron.bsuirschedule.adapter.SchedulesListAdapter.java
net.taviscaron.bsuirschedule.core.BitUtil.java
net.taviscaron.bsuirschedule.core.BsuirScheduleApplication.java
net.taviscaron.bsuirschedule.core.Constants.java
net.taviscaron.bsuirschedule.core.DateUtil.java
net.taviscaron.bsuirschedule.loader.ScheduleLoader.java
net.taviscaron.bsuirschedule.model.Lesson.java
net.taviscaron.bsuirschedule.model.LessonsListModel.java
net.taviscaron.bsuirschedule.model.Schedule.java
net.taviscaron.bsuirschedule.storage.DBHelper.java