Android Open Source - Attendance-AutoCounter D B Helper






From Project

Back to project page Attendance-AutoCounter.

License

The source code is released under:

GNU General Public License

If you think the Android project Attendance-AutoCounter 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 com.etonn.attendance_autocounter.db;
//from w ww  .j  a va  2 s.c  om
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;

/**
 * Created by Cheng on 2014/11/6.
 */
public class DBHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "database.db";
    private static final int DATABASE_VERSION = 1;

    public DBHelper(Context context, String name, CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

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

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.i("Log:DBHelper", "Create Database");
        String sql1 = "CREATE TABLE IF NOT EXISTS [attendance] (" +
                "[attendance_id] INTEGER PRIMARY KEY AUTOINCREMENT," +
                "[student_id] INTEGER," +
                "[class_id] INTEGER," +
                "[date] DATE)";

        String sql2 = "CREATE TABLE IF NOT EXISTS [classes] (" +
                "[class_id] INTEGER PRIMARY KEY AUTOINCREMENT," +
                "[class_name] VARCHAR(64)," +
                "[headcount] INT(4))";

        String sql3 = "CREATE TABLE IF NOT EXISTS [students] (" +
                "[student_id] INTEGER PRIMARY KEY AUTOINCREMENT," +
                "[name] VARCHAR(32)," +
                "[mac] CHAR(24))";

        db.execSQL(sql1);
        db.execSQL(sql2);
        db.execSQL(sql3);
    }

    //??DATABASE_VERSION????2,????????????????????,??????onUpgrade
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i("Log:DBHelper", "update a Database");
        db.execSQL("ALTER TABLE students ADD COLUMN other STRING");
    }
}




Java Source Code List

com.etonn.attendance_autocounter.ApplicationTest.java
com.etonn.attendance_autocounter.ClassActivity.java
com.etonn.attendance_autocounter.CourseModifyDialog.java
com.etonn.attendance_autocounter.EmailAbsenteeActivity.java
com.etonn.attendance_autocounter.MainActivity.java
com.etonn.attendance_autocounter.ReportActivity.java
com.etonn.attendance_autocounter.ScanningActivity.java
com.etonn.attendance_autocounter.bluetooth.BluetoothHelper.java
com.etonn.attendance_autocounter.db.Attendance.java
com.etonn.attendance_autocounter.db.Course.java
com.etonn.attendance_autocounter.db.DBHelper.java
com.etonn.attendance_autocounter.db.DBManager.java
com.etonn.attendance_autocounter.db.Student.java