Dbrant has uploaded a new change for review.
https://gerrit.wikimedia.org/r/228766
Change subject: Don't rely on column indices when fetching history from db.
......................................................................
Don't rely on column indices when fetching history from db.
This fixes a nasty bug where, because we were relying on hardcoded column
indices, we were sometimes returning a badly-formatted HistoryEntry from
the persistence helper. To wit, the MainPageReadMoreTopicTask was
receiving a HistoryEntry where the Namespace and Timestamp were switched
around, producing page titles that have a namespace of a Unix timestamp!
(e.g. "1872489743554:Irataba")
This patch changes the persistence helper to no longer use hardcoded
column indices, and instead looks up the column index by name.
Bug: T107727
Change-Id: Ifb1bd24d615c93a9b32bf85f3a5952efd40b574b
---
M
wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistenceHelper.java
1 file changed, 21 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/66/228766/1
diff --git
a/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistenceHelper.java
b/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistenceHelper.java
index 029b0ac..ed5fff1 100644
---
a/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistenceHelper.java
+++
b/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistenceHelper.java
@@ -12,30 +12,30 @@
private static final int DB_VER_NAMESPACE_ADDED = 6;
- private static final int COL_INDEX_SITE = 1;
- private static final int COL_INDEX_TITLE = 2;
- private static final int COL_INDEX_NAMESPACE = 3;
- private static final int COL_INDEX_TIMESTAMP = 4;
- private static final int COL_INDEX_SOURCE = 5;
+ private static final String COL_SITE = "site";
+ private static final String COL_TITLE = "title";
+ private static final String COL_NAMESPACE = "namespace";
+ private static final String COL_TIMESTAMP = "timestamp";
+ private static final String COL_SOURCE = "source";
@Override
public HistoryEntry fromCursor(Cursor c) {
- // Carefully, get them back by using position only
- Site site = new Site(c.getString(COL_INDEX_SITE));
- PageTitle title = new PageTitle(c.getString(COL_INDEX_NAMESPACE),
c.getString(COL_INDEX_TITLE), site);
- Date timestamp = new Date(c.getLong(COL_INDEX_TIMESTAMP));
- int source = c.getInt(COL_INDEX_SOURCE);
+ Site site = new Site(c.getString(c.getColumnIndex(COL_SITE)));
+ PageTitle title = new
PageTitle(c.getString(c.getColumnIndex(COL_NAMESPACE)),
+ c.getString(c.getColumnIndex(COL_TITLE)), site);
+ Date timestamp = new Date(c.getLong(c.getColumnIndex(COL_TIMESTAMP)));
+ int source = c.getInt(c.getColumnIndex(COL_SOURCE));
return new HistoryEntry(title, timestamp, source);
}
@Override
protected ContentValues toContentValues(HistoryEntry obj) {
ContentValues contentValues = new ContentValues();
- contentValues.put("site", obj.getTitle().getSite().getDomain());
- contentValues.put("title", obj.getTitle().getText());
- contentValues.put("namespace", obj.getTitle().getNamespace());
- contentValues.put("timestamp", obj.getTimestamp().getTime());
- contentValues.put("source", obj.getSource());
+ contentValues.put(COL_SITE, obj.getTitle().getSite().getDomain());
+ contentValues.put(COL_TITLE, obj.getTitle().getText());
+ contentValues.put(COL_NAMESPACE, obj.getTitle().getNamespace());
+ contentValues.put(COL_TIMESTAMP, obj.getTimestamp().getTime());
+ contentValues.put(COL_SOURCE, obj.getSource());
return contentValues;
}
@@ -50,14 +50,14 @@
case 1:
return new Column[] {
new Column("_id", "integer primary key"),
- new Column("site", "string"),
- new Column("title", "string"),
- new Column("timestamp", "integer"),
- new Column("source", "integer")
+ new Column(COL_SITE, "string"),
+ new Column(COL_TITLE, "string"),
+ new Column(COL_TIMESTAMP, "integer"),
+ new Column(COL_SOURCE, "integer")
};
case DB_VER_NAMESPACE_ADDED:
return new Column[] {
- new Column("namespace", "string")
+ new Column(COL_NAMESPACE, "string")
};
default:
return new Column[0];
@@ -66,7 +66,7 @@
@Override
protected String getPrimaryKeySelection() {
- return "site = ? AND title = ?";
+ return COL_SITE + " = ? AND " + COL_TITLE + " = ?";
}
@Override
--
To view, visit https://gerrit.wikimedia.org/r/228766
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb1bd24d615c93a9b32bf85f3a5952efd40b574b
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits