aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2013-01-01 15:59:40 +0100
committerSamuel Tardieu <sam@rfc1149.net>2013-01-01 16:43:41 +0100
commitc2b9669218ab2b3cc925caf59492447307785119 (patch)
tree3f2e0b345ef2583a4d3bf7f53eb08661388f9a26 /main/src
parent70207a24e2ec3c8d4e365e8117dc8da484b55d05 (diff)
downloadcgeo-c2b9669218ab2b3cc925caf59492447307785119.zip
cgeo-c2b9669218ab2b3cc925caf59492447307785119.tar.gz
cgeo-c2b9669218ab2b3cc925caf59492447307785119.tar.bz2
fix #2313: bad entries in history search
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/cgData.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index b822c2b..94eb3fd 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -387,6 +387,8 @@ public class cgData {
private static class DbHelper extends SQLiteOpenHelper {
+ private static boolean firstRun = true;
+
DbHelper(Context context) {
super(context, databasePath().getPath(), null, dbVersion);
}
@@ -671,6 +673,29 @@ public class cgData {
Log.i("Upgrade database from ver. " + oldVersion + " to ver. " + newVersion + ": completed");
}
+ @Override
+ public void onOpen(final SQLiteDatabase db) {
+ if (firstRun) {
+ sanityChecks(db);
+ firstRun = false;
+ }
+ }
+
+ /**
+ * Execute sanity checks that should be performed once per application after the database has been
+ * opened.
+ *
+ * @param db the database to perform sanity checks against
+ */
+ private static void sanityChecks(final SQLiteDatabase db) {
+ // Check that the history of searches is well formed as some dates seem to be missing according
+ // to NPE traces.
+ final int staleHistorySearches = db.delete(dbTableSearchDestionationHistory, "date is null", null);
+ if (staleHistorySearches > 0) {
+ Log.w(String.format("cgData.dbHelper.onOpen: removed %d bad search history entries", staleHistorySearches));
+ }
+ }
+
/**
* Method to remove static map files with double underscore due to issue#1670
* introduced with release on 2012-05-24.