Browse Source

Fixed unsynced changes filtering

Julien Clauter 9 years ago
parent
commit
0d66eb8a0e

+ 19 - 24
src/de/tudarmstadt/informatik/hostage/persistence/HostageDBOpenHelper.java

@@ -1567,35 +1567,30 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
 
         ArrayList<SyncDevice> updatedDevices = this.getUpdatedDevicesFor(devices, includeMissingDevices);
 
-        HashMap<String, Long> updatedDeviceMap = new HashMap<String, Long>();
-        for (SyncDevice d : updatedDevices){
-            updatedDeviceMap.put(d.getDeviceID(),d.getHighest_attack_id());
-        }
-
         ArrayList<AttackRecord> recordList = new ArrayList<AttackRecord>();
-        String selectQuery = "SELECT * FROM " + AttackEntry.TABLE_NAME + " A "
-                + " WHERE "
-                +" ( "
-                    + " A." + AttackEntry.COLUMN_NAME_DEVICE + " IN " + updatedDeviceMap.keySet()
-                + " ) "
-                //+ " GROUP BY " + AttackEntry.TABLE_NAME + "." + AttackEntry.COLUMN_NAME_DEVICE
-                + " ORDER BY " + AttackEntry.TABLE_NAME + "." + AttackEntry.COLUMN_NAME_SYNC_ID + " DESC";
+
         SQLiteDatabase db = this.getReadableDatabase();
-        Cursor cursor = db.rawQuery(selectQuery, null);
 
-        // looping through all rows and adding to list
-        if (cursor.moveToFirst()) {
-            do {
-                AttackRecord record = createAttackRecord(cursor);
-                // Adding record to list
-                if (record.getSync_id() > updatedDeviceMap.get(record.getDevice())) {
+        for (SyncDevice sDevice : updatedDevices){
+            String selectQuery = "SELECT * FROM " + AttackEntry.TABLE_NAME + " A "
+                    + " WHERE "
+                    +" ( "
+                    + " A." + AttackEntry.COLUMN_NAME_DEVICE + " = " + "'" + sDevice.getDeviceID() + "'"
+                    + " AND " + " A." + AttackEntry.COLUMN_NAME_SYNC_ID + " > " + sDevice.getHighest_attack_id()
+                    + " ) "
+                    //+ " GROUP BY " + AttackEntry.TABLE_NAME + "." + AttackEntry.COLUMN_NAME_DEVICE
+                    + " ORDER BY " + AttackEntry.TABLE_NAME + "." + AttackEntry.COLUMN_NAME_SYNC_ID + " DESC ";
+            Cursor cursor = db.rawQuery(selectQuery, null);
+
+            // looping through all rows and adding to list
+            if (cursor != null &&  cursor.moveToFirst()) {
+                do {
+                    AttackRecord record = createAttackRecord(cursor);
                     recordList.add(record);
-                } else {
-                    break;
-                }
-            } while (cursor.moveToNext());
+                } while (cursor.moveToNext());
+            }
+            cursor.close();
         }
-        cursor.close();
 
         // return record list
         db.close();