NewDBHelper.java
3.77 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.gimi.common.cinema.db;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class NewDBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "xgimi_cinema_movie.db";
private static final int DATABASE_VERSION = 5;
private static final String CREATE_TABLE = "create table movie_message(id integer primary key autoincrement," +
"name text," +
"path text UNIQUE," +
"poster_path text," +
"pinyin text," +
"md5 text," +
"type text," +
"douban_id text)";
public static final String TABLE_NAME = "movie_message";
public static final String ID = "id";
public static final String NAME = "name";
public static final String PATH = "path";
public static final String POSTER_PATH = "poster_path";
public static final String PINYIN = "pinyin";
public static final String TYPE = "type";
public static final String DOUBAN_ID = "douban_id";
public static final String MD5 = "md5";
public static final String CLASS_DESCRIBE = "class_describe";
public static final String MOVIE_LENGTH = "movie_length";
public static final String DOUBAN_RATING = "douban_rating";
public static final String LAST_PLAY_TIME = "last_play_time";
public static final String SCREEN_TIME = "screen_time";
public static final String MOVIE_COUNT = "movie_count";
public static final String MOVIE_DL_TIME = "movie_dl_time";
public NewDBHelper(Context context) {
//CursorFactory设置为null,使用默认值
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
//数据库第一次被创建时onCreate会被调用
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
db.execSQL(ADD_COLUMNS);
db.execSQL(ADD_COLUMNS1);
db.execSQL(ADD_COLUMNS2);
db.execSQL(ADD_COLUMNS3);
db.execSQL(ADD_COLUMNS4);
db.execSQL(ADD_COLUMNS5);
db.execSQL(ADD_COLUMNS6);
}
private static final String ADD_COLUMNS = "ALTER TABLE movie_message ADD class_describe TEXT";
private static final String ADD_COLUMNS1 = "ALTER TABLE movie_message ADD movie_length TEXT";
private static final String ADD_COLUMNS2 = "ALTER TABLE movie_message ADD douban_rating TEXT";
private static final String ADD_COLUMNS3 = "ALTER TABLE movie_message ADD last_play_time TEXT";
private static final String ADD_COLUMNS4 = "ALTER TABLE movie_message ADD screen_time TEXT";
private static final String ADD_COLUMNS5 = "ALTER TABLE movie_message ADD movie_count TEXT";
private static final String ADD_COLUMNS6 = "ALTER TABLE movie_message ADD movie_dl_time TEXT";
private static final String DROP_TABLE = "drop table if exists movie_message";
//如果DATABASE_VERSION值被改为2,系统发现现有数据库版本不同,即会调用onUpgrade
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (newVersion != oldVersion) {
db.execSQL(DROP_TABLE);
onCreate(db);
}
}
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (newVersion != oldVersion) {
db.execSQL(DROP_TABLE);
onCreate(db);
}
}
}