summaryrefslogtreecommitdiffstats
path: root/src/ryuslash/org/dvdroid/SQLiteHelper.java
blob: c2ec71e2d064cfedcf71327e7482ee8e4cdb2a30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package ryuslash.org.dvdroid;

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

public class SQLiteHelper extends SQLiteOpenHelper
{
    public static final String TABLE_DVD = "dvd";
    public static final String COLUMN_ID = "id";
    public static final String COLUMN_TITLE = "title";
    public static final String COLUMN_WATCHED = "watched";
    public static final String COLUMN_WISHLIST = "wishlist";

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

    private static final String TABLE_DVD_CREATE =
        "create table " + TABLE_DVD + " ("
        + COLUMN_ID + " integer primary key autoincrement, "
        + COLUMN_TITLE + " text not null, "
        + COLUMN_WATCHED + " integer not null, "
        + COLUMN_WISHLIST + " integer not null"
        + ");";

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

    @Override
    public void onCreate(SQLiteDatabase database)
    {
        database.execSQL(TABLE_DVD_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldV, int newV)
    {
        Log.w(SQLiteHelper.class.getName(),
              "Upgrading database from version " + oldV + " to "
              + newV + ", whech will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_DVD);
        onCreate(db);
    }
}