Browse Source

Add deletion triggers to DB tables

master
Chris Smith 14 years ago
parent
commit
58c6e94d68

BIN
code/ContextAnalyser/dist/ContextAnalyser.apk View File


+ 16
- 1
code/ContextAnalyser/src/uk/co/md87/android/contextanalyser/DataHelper.java View File

@@ -53,7 +53,7 @@ public class DataHelper {
53 53
     public static final String JOURNEYSTEPS_TABLE = "journeysteps";
54 54
 
55 55
     private static final String DATABASE_NAME = "contextapi.db";
56
-    private static final int DATABASE_VERSION = 7;
56
+    private static final int DATABASE_VERSION = 8;
57 57
 
58 58
     private static final String INSERT_LOCATION = "insert into "
59 59
       + LOCATIONS_TABLE + "(name, lat, lon) values (?, ?, ?)";
@@ -270,6 +270,19 @@ public class DataHelper {
270 270
             db.execSQL("CREATE TABLE " + JOURNEYSTEPS_TABLE
271 271
                     + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, activity TEXT,"
272 272
                     + " repetitions INTEGER, journey INTEGER, next INTEGER)");
273
+
274
+            createTriggers(db);
275
+        }
276
+
277
+        public void createTriggers(final SQLiteDatabase db) {
278
+            db.execSQL("CREATE TRIGGER fkd_journeys_place_id BEFORE DELETE ON "
279
+                    + LOCATIONS_TABLE + " FOR EACH ROW BEGIN "
280
+                    + "DELETE FROM " + JOURNEYS_TABLE + " WHERE start = OLD._id"
281
+                    + " OR end = OLD._id; END;");
282
+            db.execSQL("CREATE TRIGGER fkd_journey_steps_journey_id BEFORE DELETE ON "
283
+                    + JOURNEYS_TABLE + " FOR EACH ROW BEGIN "
284
+                    + "DELETE FROM " + JOURNEYSTEPS_TABLE + " WHERE journey = OLD._id"
285
+                    + "; END;");
273 286
         }
274 287
 
275 288
         /** {@inheritDoc} */
@@ -285,6 +298,8 @@ public class DataHelper {
285 298
                 db.execSQL("DROP TABLE " + JOURNEYS_TABLE);
286 299
                 db.execSQL("DROP TABLE " + JOURNEYSTEPS_TABLE);
287 300
                 onCreate(db);
301
+            } else if (oldVersion <= 8) {
302
+                createTriggers(db);
288 303
             }
289 304
         }
290 305
 

Loading…
Cancel
Save