· 9 years ago · Jan 15, 2017, 12:16 AM
1 /* Common constants */
2 private static final int DB_VERSION = 7;
3 private static final String DB_NAME = "WhereToPeeDatabase";
4 private static final String DB_USER_TABLE = "User";
5 private static final String DB_COORDINATES_TABLE = "Coordinates";
6 private static final String DB_TOILET_TABLE = "Toilet";
7
8 public static final String KEY_ID = "id";
9 public static final String ID_OPTIONS = "INTEGER PRIMARY KEY AUTOINCREMENT";
10 public static final int ID_COLUMN = 0;
11
12 /* User database constants */
13 public static final String KEY_NICKNAME = "nickname";
14 public static final String NICKNAME_OPITONS = "TEXT NOT NULL";
15 public static final int NICKNAME_COLUMN = 1;
16
17 public static final String KEY_PHONEINFO = "phoneinfo";
18 public static final String PHONEINFO_OPITONS = "TEXT"; // can be NULL
19 public static final int PHONEINFO_COLUMN = 2;
20
21 /* Coordinates database constants */
22 public static final String KEY_LATITUDE = "latitude";
23 public static final String LATITUDE_OPITONS = "REAL NOT NULL";
24 public static final int LATITUDE_COLUMN = 1;
25
26 public static final String KEY_LONGITUDE = "longitude";
27 public static final String LONGITUDE_OPITONS = "REAL NOT NULL";
28 public static final int LONGITUDE_COLUMN = 2;
29
30 /* Toilet database constants */
31 public static final String KEY_COORDINATES = "coordinates";
32 public static final String COORDINATES_OPITONS = "INTEGER REFERENCES Coordinates(id) NOT NULL UNIQUE"; // can't have two toilets in the same location
33 public static final int COORDINATES_COLUMN = 1;
34
35 public static final String KEY_USERWHOADDED = "userWhoAdded";
36 public static final String USERWHOADDED_OPITONS = "INTEGER REFERENCES User(id) NOT NULL";
37 public static final int USERWHOADDED_COLUMN = 2;
38
39 public static final String KEY_DESCRIPTION = "description";
40 public static final String DESCRIPTION_OPITONS = "TEXT NOT NULL";
41 public static final int DESCRIPTION_COLUMN = 3;
42
43 public static final String KEY_HASCHANGINGTABLE = "hasChangingTable";
44 public static final String HASCHANGINGTABLE_OPITONS = "INTEGER NOT NULL CHECK (hasChangingTable = 0 OR hasChangingTable = 1)";
45 public static final int HASCHANGINGTABLE_COLUMN = 4;
46
47 public static final String KEY_DISABLEDACCESSIBLE = "disabledAccesible";
48 public static final String DISABLEDACCESSIBLE_OPITONS = "INTEGER NOT NULL CHECK (disabledAccesible = 0 OR disabledAccesible = 1)";
49 public static final int DISABLEDACCESSIBLE_COLUMN = 5;
50
51 public static final String KEY_ISFREE = "isFree";
52 public static final String ISFREE_OPITONS = "INTEGER NOT NULL CHECK (isFree = 0 OR isFree = 1)";
53 public static final int ISFREE_COLUMN = 6;
54
55 public static final String KEY_ACCEPTEDBYADMIN = "acceptedByAdmin";
56 public static final String ACCEPTEDBYADMIN_OPITONS = "INTEGER NOT NULL DEFAULT 0 CHECK (acceptedByAdmin = 0 OR acceptedByAdmin = 1)";
57 public static final int ACCEPTEDBYADMIN_COLUMN = 7;
58
59 /* Creates User table */
60 private static final String DB_CREATE_USER_TABLE =
61 "CREATE TABLE " + DB_USER_TABLE + "(" +
62 KEY_ID + " " + ID_OPTIONS + ", " +
63 KEY_NICKNAME + " " + NICKNAME_OPITONS + ", " +
64 KEY_PHONEINFO + " " + PHONEINFO_OPITONS +
65 ");";
66 /* Drops User table */
67 private static final String DB_DROP_USER_TABLE =
68 "DROP TABLE IF EXISTS " + DB_USER_TABLE;
69
70 /* Creates User table */
71 private static final String DB_CREATE_COORDINATES_TABLE =
72 "CREATE TABLE " + DB_COORDINATES_TABLE + "(" +
73 KEY_ID + " " + ID_OPTIONS + ", "+
74 KEY_LATITUDE + " " + LATITUDE_OPITONS + ", " +
75 KEY_LONGITUDE + " " + LONGITUDE_OPITONS +
76 ");";
77
78 /* Drops User table */
79 private static final String DB_DROP_COORDINATES_TABLE =
80 "DROP TABLE IF EXISTS " + DB_COORDINATES_TABLE;
81
82 /* Creates User table */
83 private static final String DB_CREATE_TOILET_TABLE =
84 "CREATE TABLE " + DB_TOILET_TABLE + "(" +
85 KEY_ID + " " + ID_OPTIONS + ", " +
86 KEY_COORDINATES + " " + COORDINATES_OPITONS + ", " +
87 KEY_USERWHOADDED + " " + USERWHOADDED_OPITONS + ", " +
88 KEY_DESCRIPTION + " " + DESCRIPTION_OPITONS + ", " +
89 KEY_HASCHANGINGTABLE + " " + HASCHANGINGTABLE_OPITONS + ", " +
90 KEY_DISABLEDACCESSIBLE + " " + DISABLEDACCESSIBLE_OPITONS + ", " +
91 KEY_ISFREE + " " + ISFREE_OPITONS + ", " +
92 KEY_ACCEPTEDBYADMIN + " " + ACCEPTEDBYADMIN_OPITONS +
93 ");";
94
95 /* Drops User table */
96 private static final String DB_DROP_TOILET_TABLE =
97 "DROP TABLE IF EXISTS " + DB_TOILET_TABLE;