Bug 1428165 - Part 2: fix history expiration query r=nalexander
'modified' value might be missing; in SQLite, max(123, null) is null, and so we must
coalesce fields which might be missing values.
MozReview-Commit-ID: Bn1P0kdaHHT
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
@@ -473,18 +473,22 @@ public class BrowserProvider extends Sha
return;
}
final long toRemove = rows - retain;
debug("Expiring at most " + toRemove + " rows earlier than " + keepAfter + ".");
final String sql;
if (keepAfter > 0) {
+ // See Bug 1428165: 'modified' value might be missing; assume 0 if that's the case.
sql = "DELETE FROM " + TABLE_HISTORY + " " +
- "WHERE MAX(" + History.DATE_LAST_VISITED + ", " + History.DATE_MODIFIED + ") < " + keepAfter + " " +
+ "WHERE MAX("
+ + History.DATE_LAST_VISITED + ", " +
+ "COALESCE(" + History.DATE_MODIFIED + ", 0))" +
+ " < " + keepAfter + " " +
" AND " + History._ID + " IN ( SELECT " +
History._ID + " FROM " + TABLE_HISTORY + " " +
"ORDER BY " + History.DATE_LAST_VISITED + " ASC LIMIT " + toRemove +
")";
} else {
sql = "DELETE FROM " + TABLE_HISTORY + " WHERE " + History._ID + " " +
"IN ( SELECT " + History._ID + " FROM " + TABLE_HISTORY + " " +
"ORDER BY " + History.DATE_LAST_VISITED + " ASC LIMIT " + toRemove + ")";