Bug 1234315 - Convert getMobileFolderId into getFolderIDForGuid r?rnewman
We only use this in one location, so there's little advantage to storing our parameters
as static final. Allowing arbitrary guids will allow us to retrieve e.g. the reading
list folder id easily in future.
MozReview-Commit-ID: JnLsgKAr1Y0
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
@@ -71,19 +71,16 @@ public final class BrowserDatabaseHelper
static final String TABLE_HISTORY_JOIN_FAVICONS = TABLE_HISTORY + " LEFT OUTER JOIN " +
TABLE_FAVICONS + " ON " + qualifyColumn(TABLE_HISTORY, History.FAVICON_ID) + " = " +
qualifyColumn(TABLE_FAVICONS, Favicons._ID);
static final String TABLE_BOOKMARKS_TMP = TABLE_BOOKMARKS + "_tmp";
static final String TABLE_HISTORY_TMP = TABLE_HISTORY + "_tmp";
- private static final String[] mobileIdColumns = new String[] { Bookmarks._ID };
- private static final String[] mobileIdSelectionArgs = new String[] { Bookmarks.MOBILE_FOLDER_GUID };
-
public BrowserDatabaseHelper(Context context, String databasePath) {
super(context, databasePath, null, DATABASE_VERSION);
mContext = context;
}
private void createBookmarksTable(SQLiteDatabase db) {
debug("Creating " + TABLE_BOOKMARKS + " table");
@@ -693,17 +690,17 @@ public final class BrowserDatabaseHelper
c.close();
}
// At this point is safe to assume that the mobile folder is
// in the new table given that we've always created it on
// database creation time.
final int nInvalidSpecialEntries = invalidSpecialEntries.size();
if (nInvalidSpecialEntries > 0) {
- Integer mobileFolderId = getMobileFolderId(db);
+ Integer mobileFolderId = getBookmarkIdForGuid(db, Bookmarks.MOBILE_FOLDER_GUID);
if (mobileFolderId == null) {
Log.e(LOGTAG, "Error migrating invalid special folder entries: mobile folder id is null");
return;
}
debug("Found " + nInvalidSpecialEntries + " invalid special folder entries");
for (int i = 0; i < nInvalidSpecialEntries; i++) {
ContentValues values = invalidSpecialEntries.get(i);
@@ -1303,24 +1300,24 @@ public final class BrowserDatabaseHelper
}
protected static void debug(String message) {
if (logDebug) {
Log.d(LOGTAG, message);
}
}
- private Integer getMobileFolderId(SQLiteDatabase db) {
+ private Integer getBookmarkIdForGuid(SQLiteDatabase db, final String guid) {
Cursor c = null;
try {
c = db.query(TABLE_BOOKMARKS,
- mobileIdColumns,
+ new String[] { Bookmarks._ID },
Bookmarks.GUID + " = ?",
- mobileIdSelectionArgs,
+ new String[] { guid },
null, null, null);
if (c == null || !c.moveToFirst())
return null;
return c.getInt(c.getColumnIndex(Bookmarks._ID));
} finally {
if (c != null)