· 8 years ago · Feb 22, 2018, 01:28 PM
1package com.example.z4kbr.travelcompanion.DB;
2
3import android.content.Context;
4import android.database.sqlite.SQLiteDatabase;
5import android.database.sqlite.SQLiteOpenHelper;
6
7public class DatabaseOpenHelper extends SQLiteOpenHelper {
8
9 // if you change the database schema, you must increment the database version.
10 public static final int DATABASE_VERSION = 7;
11 // this is used to name the underlying file storing the actual data
12 public static final String DATABASE_NAME = "entries.db";
13
14 public DatabaseOpenHelper(Context context) {
15 super(context, DATABASE_NAME, null, DATABASE_VERSION);
16 }
17
18 public void onCreate(SQLiteDatabase db) {
19 db.execSQL(SQL_CREATE_BLOG_ENTRIES);
20 }
21
22 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
23 // in our case, we simply delete all data and recreate the DB
24 db.execSQL(SQL_DELETE_BLOG_ENTRIES);
25 onCreate(db);
26 }
27
28 private static final String SQL_CREATE_BLOG_ENTRIES =
29 "CREATE TABLE entries (" +
30 "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
31 "item TEXT NOT NULL "+
32 ")";
33
34 private static final String SQL_DELETE_BLOG_ENTRIES =
35 "DROP TABLE IF EXISTS entries";
36}