diff --git a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherMigrationHelper.java b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherMigrationHelper.java index b7e2986194..b1a58efedd 100644 --- a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherMigrationHelper.java +++ b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherMigrationHelper.java @@ -25,6 +25,8 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.whispersystems.libsignal.InvalidMessageException; import java.io.IOException; +import java.util.HashSet; +import java.util.Set; public class SQLCipherMigrationHelper { @@ -180,6 +182,8 @@ public class SQLCipherMigrationHelper { @NonNull net.sqlcipher.database.SQLiteDatabase modernDb, @Nullable BiFunction, ContentValues> transformer) { + Set destinationColumns = getTableColumns(tableName, modernDb); + try (Cursor cursor = legacyDb.query(tableName, null, null, null, null, null, null)) { int count = (cursor != null) ? cursor.getCount() : 0; int progress = 1; @@ -190,11 +194,13 @@ public class SQLCipherMigrationHelper { for (int i=0;i(type, body); } + private static Set getTableColumns(String tableName, net.sqlcipher.database.SQLiteDatabase database) { + Set results = new HashSet<>(); + + try (Cursor cursor = database.rawQuery("PRAGMA table_info(" + tableName + ")", null)) { + while (cursor != null && cursor.moveToNext()) { + results.add(cursor.getString(1)); + } + } + + return results; + } + private static int getTotalProgress(int sectionOffset, int sectionProgress, int sectionTotal) { double percentOfSectionComplete = ((double)sectionProgress) / ((double)sectionTotal); return sectionOffset + (int)(((double)1000) * percentOfSectionComplete);