From 8661aad33f9a23e2900e4f4409ed84114b0feb54 Mon Sep 17 00:00:00 2001 From: neraud Date: Sun, 14 Jun 2015 11:41:13 +0200 Subject: [PATCH] Fixed #83 : Deleted corrupted leaders --- .../sqlite/PADListenerSQLiteOpenHelper.java | 2 +- .../CapturedPlayerFriendLeaderTable.java | 22 +++++++++++++++---- .../src/main/res/xml/changelog_master.xml | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/PADListenerApp/src/main/java/fr/neraud/padlistener/provider/sqlite/PADListenerSQLiteOpenHelper.java b/PADListenerApp/src/main/java/fr/neraud/padlistener/provider/sqlite/PADListenerSQLiteOpenHelper.java index e07943c..db2e94f 100644 --- a/PADListenerApp/src/main/java/fr/neraud/padlistener/provider/sqlite/PADListenerSQLiteOpenHelper.java +++ b/PADListenerApp/src/main/java/fr/neraud/padlistener/provider/sqlite/PADListenerSQLiteOpenHelper.java @@ -22,7 +22,7 @@ */ public class PADListenerSQLiteOpenHelper extends SQLiteOpenHelper { - private static final int DB_VERSION = 11; + private static final int DB_VERSION = 12; private static final String DATABASE_NAME = "padlistener.db"; private static final List TABLES = new ArrayList(); diff --git a/PADListenerApp/src/main/java/fr/neraud/padlistener/provider/sqlite/tables/CapturedPlayerFriendLeaderTable.java b/PADListenerApp/src/main/java/fr/neraud/padlistener/provider/sqlite/tables/CapturedPlayerFriendLeaderTable.java index 119b8e6..76b2873 100644 --- a/PADListenerApp/src/main/java/fr/neraud/padlistener/provider/sqlite/tables/CapturedPlayerFriendLeaderTable.java +++ b/PADListenerApp/src/main/java/fr/neraud/padlistener/provider/sqlite/tables/CapturedPlayerFriendLeaderTable.java @@ -40,7 +40,7 @@ public String dropTable() { @Override public int getVersion() { - return 11; + return 12; } @Override @@ -48,9 +48,22 @@ public List upgrade(int oldVersion, int newVersion) { final List queries = new ArrayList(); if (oldVersion < getVersion()) { - MyLog.warn("Table " + CapturedPlayerFriendLeaderDescriptor.TABLE_NAME + " has changed, destroying table !"); - queries.add(dropTable()); - queries.add(createTable()); + if (oldVersion == 11 && newVersion == 12) { + MyLog.debug("Deleting corrupted leaders"); + final StringBuilder queryBuilder = new StringBuilder("DELETE FROM "); + queryBuilder.append(CapturedPlayerFriendLeaderDescriptor.TABLE_NAME); + queryBuilder.append(" WHERE ").append(CapturedPlayerFriendLeaderDescriptor.Fields.ID_JP.getColName()).append(" = -1"); + queryBuilder.append(" OR ").append(CapturedPlayerFriendLeaderDescriptor.Fields.SKILL_LEVEL.getColName()).append(" > 50"); + queryBuilder.append(" OR ").append(CapturedPlayerFriendLeaderDescriptor.Fields.PLUS_HP.getColName()).append(" > 99"); + queryBuilder.append(" OR ").append(CapturedPlayerFriendLeaderDescriptor.Fields.PLUS_ATK.getColName()).append(" > 99"); + queryBuilder.append(" OR ").append(CapturedPlayerFriendLeaderDescriptor.Fields.PLUS_RCV.getColName()).append(" > 99"); + queryBuilder.append(" OR ").append(CapturedPlayerFriendLeaderDescriptor.Fields.AWAKENINGS.getColName()).append(" > 25"); + queries.add(queryBuilder.toString()); + } else { + MyLog.warn("Table " + CapturedPlayerFriendLeaderDescriptor.TABLE_NAME + " has changed, destroying table !"); + queries.add(dropTable()); + queries.add(createTable()); + } } else { MyLog.info("Table " + CapturedPlayerFriendLeaderDescriptor.TABLE_NAME + " is already up to date (hasn't changed since version " + getVersion() + ")"); } @@ -65,5 +78,6 @@ public void preUpgrade(Context context, int oldVersion, int newVersion) { @Override public void postUpgrade(Context context, int oldVersion, int newVersion) { + } } diff --git a/PADListenerApp/src/main/res/xml/changelog_master.xml b/PADListenerApp/src/main/res/xml/changelog_master.xml index d2c8cec..169f208 100644 --- a/PADListenerApp/src/main/res/xml/changelog_master.xml +++ b/PADListenerApp/src/main/res/xml/changelog_master.xml @@ -2,7 +2,7 @@ - Fixed #83 : Friends' leader broken + Fixed #83 : Friends' leader broken and deleted corrupted leaders