Skip to content

Commit cb3094b

Browse files
Fix DB update issue (#5016)
1 parent c520024 commit cb3094b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

app/src/main/java/fr/free/nrw/commons/category/CategoryDao.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ List<CategoryItem> recentCategories(int limit) {
9393
// fixme add a limit on the original query instead of falling out of the loop?
9494
while (cursor != null && cursor.moveToNext()
9595
&& cursor.getPosition() < limit) {
96-
items.add(new CategoryItem(fromCursor(cursor).getName(),
97-
fromCursor(cursor).getDescription(), fromCursor(cursor).getThumbnail(),
98-
false));
96+
if (fromCursor(cursor).getName() != null ) {
97+
items.add(new CategoryItem(fromCursor(cursor).getName(),
98+
fromCursor(cursor).getDescription(), fromCursor(cursor).getThumbnail(),
99+
false));
100+
}
99101
}
100102
} catch (RemoteException e) {
101103
throw new RuntimeException(e);
@@ -193,6 +195,13 @@ public static void onUpdate(SQLiteDatabase db, int from, int to) {
193195
onUpdate(db, from, to);
194196
return;
195197
}
198+
if (from == 17) {
199+
db.execSQL("ALTER TABLE categories ADD COLUMN description STRING;");
200+
db.execSQL("ALTER TABLE categories ADD COLUMN thumbnail STRING;");
201+
from++;
202+
onUpdate(db, from, to);
203+
return;
204+
}
196205
}
197206
}
198207
}

app/src/main/java/fr/free/nrw/commons/category/CategoryItem.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import android.os.Parcelable
44
import kotlinx.android.parcel.Parcelize
55

66
@Parcelize
7-
data class CategoryItem(val name: String, val description: String,
8-
val thumbnail: String, var isSelected: Boolean) : Parcelable {
7+
data class CategoryItem(val name: String, val description: String?,
8+
val thumbnail: String?, var isSelected: Boolean) : Parcelable {
99

1010
override fun toString(): String {
1111
return "CategoryItem: '$name'"

0 commit comments

Comments
 (0)