· 7 years ago · Dec 11, 2018, 08:10 AM
1package com.layerfarm.setting;
2
3import android.content.Context;
4import android.database.sqlite.SQLiteDatabase;
5import android.database.sqlite.SQLiteOpenHelper;
6import android.util.Log;
7
8import android.widget.Toast;
9
10
11public class DataHelper extends SQLiteOpenHelper {
12
13 private static final String LOGCAT = null;
14 private static final String DATABASE_NAME = "layerfarm-mobile.db";
15 private static final int DATABASE_VERSION = 1;
16
17 public static final String locationSQL = "CREATE TABLE IF NOT EXISTS location(id integer primary key, name text, address text, rid integer);";
18 public static final String eqq_qualitySQL = "CREATE TABLE IF NOT EXISTS eqq_quality(id integer primary key, name text);";
19
20 public DataHelper(Context context) {
21 super(context, DATABASE_NAME, null, DATABASE_VERSION);
22 Log.d(LOGCAT,"Created");
23 // TODO Auto-generated constructor stub
24 }
25
26 @Override
27 public void onCreate(SQLiteDatabase db) {
28 try {
29 //Create table
30 db.execSQL(locationSQL);
31 db.execSQL(eqq_qualitySQL);
32
33 String InsertlocationSQL = "INSERT INTO location (id, name, address, rid) VALUES " +
34 "(1,'Location A','Blitar',1)," +
35 "(2,'Location B','Blitar',2)," +
36 "(3,'Location C','Blitar',3)," +
37 "(4,'Location D','Blitar',4);";
38 db.execSQL(InsertlocationSQL);
39
40 String InsertEggQualitySQL = "INSERT INTO egg_quality (id, name) VALUES " +
41 "(1,'Quality A'), " +
42 "(2,'Quality B'), " +
43 "(3,'Quality C'), " +
44 "(4,'Cracked');";
45 db.execSQL(InsertEggQualitySQL);
46 }catch (Exception e){
47 e.printStackTrace();
48 }
49 }
50
51
52 @Override
53 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
54
55 // Drop table if existed, all data will be gone!!!
56 db.execSQL("DROP TABLE IF EXISTS location;"); db.execSQL("DROP TABLE IF EXISTS eqq_quality;"); onCreate(db);
57 }
58
59}