Skip to content

Commit a6d0262

Browse files
committed
feat(download): add ARCHIVE_URI column handling
1 parent 289115d commit a6d0262

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

app/src/main/java/com/hippo/ehviewer/EhDB.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,13 +895,24 @@ private static <T> boolean copyDao(AbstractDao<T, ?> from, AbstractDao<T, ?> to)
895895
}
896896
} catch (IOException e) {
897897
return false;
898+
} catch (SQLiteException e) {
899+
Log.e(TAG, "Failed to copy DAO data", e);
900+
return false;
898901
}
899902
return true;
900903
}
901904

902905
public static synchronized boolean exportDB(Context context, File file) {
903906
final String ehExportName = "eh.export.db";
904907

908+
// Ensure source database has ARCHIVE_URI column
909+
try {
910+
sDaoSession.getDatabase().execSQL("ALTER TABLE \"DOWNLOADS\" ADD COLUMN \"ARCHIVE_URI\" TEXT");
911+
} catch (Exception e) {
912+
// Column might already exist, ignore the error
913+
Log.d(TAG, "ARCHIVE_URI column already exists or failed to add", e);
914+
}
915+
905916
// Delete old export db
906917
context.deleteDatabase(ehExportName);
907918

@@ -912,7 +923,7 @@ public static synchronized boolean exportDB(Context context, File file) {
912923
try (SQLiteDatabase db = helper.getWritableDatabase()) {
913924
DaoMaster daoMaster = new DaoMaster(db);
914925
DaoSession exportSession = daoMaster.newSession();
915-
if (!copyDao(sDaoSession.getDownloadsDao(), exportSession.getDownloadsDao()))
926+
if (! copyDao(sDaoSession.getDownloadsDao(), exportSession.getDownloadsDao()))
916927
return false;
917928
if (!copyDao(sDaoSession.getDownloadLabelDao(), exportSession.getDownloadLabelDao()))
918929
return false;

app/src/main/java/com/hippo/ehviewer/dao/DownloadsDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void createTable(Database db, boolean ifNotExists) {
4747
"\"STATE\" INTEGER NOT NULL ," + // 10: state
4848
"\"LEGACY\" INTEGER NOT NULL ," + // 11: legacy
4949
"\"TIME\" INTEGER NOT NULL ," + // 12: time
50-
"\"LABEL\" TEXT);" + // 13: label
50+
"\"LABEL\" TEXT," + // 13: label
5151
"\"ARCHIVE_URI\" TEXT);"); // 14: archiveUri
5252
}
5353

0 commit comments

Comments
 (0)