· 6 years ago · Aug 26, 2019, 10:56 AM
1public class DatabaseHelper extends SQLiteOpenHelper{
2
3 public static String DATABASE_NAME = "dbmovie";
4
5 private static final int DATABASE_VERSION = 1;
6
7 private static final String CREATE_TABLE_MOVIES = "create table " + TABLE_MOVIES + " (" +
8 BaseColumns._ID + " integer primary key unique, " +
9 TITLE + " text not null, " +
10 DESCRIPTION + " text not null, " +
11 POSTER + " text not null);";
12
13 private static final String CREATE_TABLE_TV = "create table " + TABLE_TV + " (" +
14 _ID + " integer primary key unique, " +
15 TITLE + " text not null, " +
16 DESCRIPTION + " text not null, " +
17 POSTER + " text not null);";
18
19 public DatabaseHelper(Context context) {
20 super(context, DATABASE_NAME, null, DATABASE_VERSION);
21 }
22
23 @Override
24 public void onCreate(SQLiteDatabase sqLiteDatabase) {
25 sqLiteDatabase.execSQL(CREATE_TABLE_MOVIES);
26 sqLiteDatabase.execSQL(CREATE_TABLE_TV);
27 }
28
29 @Override
30 public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
31 sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_MOVIES);
32 sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_TV);
33 onCreate(sqLiteDatabase);
34 }
35}