aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/cgData.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/cgData.java')
-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 78611b8..e8865c7 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -372,6 +372,8 @@ public class cgData {
private static class DbHelper extends SQLiteOpenHelper {
+ private static boolean firstRun = true;
+
DbHelper(Context context) {
super(context, databasePath().getPath(), null, dbVersion);
}
@@ -665,6 +667,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.