- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDBHelper.java
More file actions
Latest commit
41 lines (35 loc) · 1.37 KB
/
Copy pathDBHelper.java
File metadata and controls
41 lines (35 loc) · 1.37 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
packagecom.momo.mvp_demo;
importandroid.content.Context;
importandroid.database.sqlite.SQLiteDatabase;
importandroid.database.sqlite.SQLiteOpenHelper;
/**
* Created by RealMo on 2016-12-23.
*/
publicclassDBHelperextendsSQLiteOpenHelper {
privatefinalstaticStringDBNAME = "my.db";
privatefinalstaticStringUSER = "user";
privatefinalstaticStringFOOD = "food";
privatefinalstaticStringPERSON = "person";
privatefinalstaticintSTARTVERSION = 1;
privatefinalstaticintCURRENTVERSION = 3;
publicDBHelper(Contextcontext) {
super(context, DBNAME, null, CURRENTVERSION);
}
@Override
publicvoidonCreate(SQLiteDatabasedb) {
db.execSQL("CREATE TABLE IF NOT EXISTS " + USER + "(_id INTEGER PRIMARY KEY AUTOINCREMENT,USERNAME,PASSWORD)");
onUpgrade(db, STARTVERSION, CURRENTVERSION);
}
@Override
publicvoidonUpgrade(SQLiteDatabasedb, intoldVersion, intnewVersion) {
switch (oldVersion) {
case1:
//添加FOOD
db.execSQL("CREATE TABLE IF NOT EXISTS " + FOOD + "(_id INTEGER PRIMARY KEY AUTOINCREMENT,USERNAME,PASSWORD)");
case2:
//添加PERSON
db.execSQL("CREATE TABLE IF NOT EXISTS " + PERSON + "(_id INTEGER PRIMARY KEY AUTOINCREMENT,USERNAME,PASSWORD)");
break;
}
}
}