· 8 years ago · Jan 05, 2018, 07:04 AM
1package com.SyKoM.Logic;
2
3import android.content.Context;
4import android.database.sqlite.SQLiteDatabase;
5import android.database.sqlite.SQLiteOpenHelper;
6import android.util.Log;
7
8
9public class Database extends SQLiteOpenHelper {
10
11
12 private static final String DATABASE_NAME = "security_profiles.db";
13 private static final int DATABASE_VERSION = 1;
14
15 public Database(Context context) {
16 super(context, DATABASE_NAME, null, DATABASE_VERSION);
17 }
18
19 @Override
20 public void onCreate(SQLiteDatabase db) {
21 String CREATE_SECURITY_PROFILES = "CREATE TABLE IF NOT EXISTS SecurityProfiles ("
22 + "id integer PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,"
23 + "Name varchar(50) NOT NULL UNIQUE);";
24
25 String CREATE_APPLICATIONS = "CREATE TABLE IF NOT EXISTS Applications ("
26 + "id integer PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,"
27 + "Uid integer NOT NULL UNIQUE,"
28 + "fkSecurityProfile integer,"
29 + "FOREIGN KEY (fkSecurityProfile) "
30 + "REFERENCES SecurityProfiles(id) "
31 + "ON DELETE NO ACTION "
32 + "ON UPDATE NO ACTION);";
33
34 String CREATE_DATAS = "CREATE TABLE IF NOT EXISTS Datas ("
35 + "id integer PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,"
36 + "DisplayName varchar(200) NOT NULL,"
37 + "DataType integer NOT NULL,"
38 + "AndroidId varchar(100) NOT NULL,"
39 + "ThumbPath varchar(150),"
40 + "fkSecurityProfile integer,"
41 + "FOREIGN KEY (fkSecurityProfile) "
42 + "REFERENCES SecurityProfiles(id) "
43 + "ON DELETE NO ACTION "
44 + "ON UPDATE NO ACTION);";
45
46 String CREATE_CONTEXTS = "CREATE TABLE Contexts ("
47 + "id integer PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,"
48 + "Name varchar(50),"
49 + "StartH integer,"
50 + "StartM integer,"
51 + "EndH integer,"
52 + "EndM integer,"
53 + "DayOfWeek varchar(8),"
54 + "Latitude float(50,8),"
55 + "Longitude float(50,8),"
56 + "fkSecurityProfile integer,"
57 + "FOREIGN KEY (fkSecurityProfile) "
58 + "REFERENCES SecurityProfiles(id) "
59 + "ON DELETE NO ACTION "
60 + "ON UPDATE NO ACTION);";
61
62 Log.d("CREATE", "onCreate: " + CREATE_APPLICATIONS);
63 db.execSQL(CREATE_APPLICATIONS);
64
65 Log.d("CREATE", "onCreate: " + CREATE_CONTEXTS);
66 db.execSQL(CREATE_CONTEXTS);
67
68 Log.d("CREATE", "onCreate: " + CREATE_DATAS);
69 db.execSQL(CREATE_DATAS);
70
71 Log.d("CREATE", "onCreate: " + CREATE_SECURITY_PROFILES);
72 db.execSQL(CREATE_SECURITY_PROFILES);
73 }
74
75 @Override
76 public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
77 // TODO Auto-generated method stub
78 }
79}