diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-03-14 20:39:24 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-03-14 20:39:24 +0100 |
commit | ab0d3c397493377eb98f9713fc669fb5ec72a45b (patch) | |
tree | cd7486e1fc92e021f5bc03b797e13127282950e4 | |
parent | c529b0139dd8a5a3f48f4c974daa8d69a1275ed3 (diff) |
fix backup creation for older installations
If you had problems importing the backup you need to create a new backup after this patch
-rw-r--r-- | src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java | 5 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/services/ExportBackupService.java | 19 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 8336a4ed9..e2c83321d 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -60,7 +60,7 @@ import rocks.xmpp.addr.Jid; public class DatabaseBackend extends SQLiteOpenHelper { public static final String DATABASE_NAME = "history"; - public static final int DATABASE_VERSION = 46; // = Conversations DATABASE_VERSION + 2 + public static final int DATABASE_VERSION = 47; // = Conversations DATABASE_VERSION + 3 private static DatabaseBackend instance = null; private static String CREATE_CONTATCS_STATEMENT = "create table " @@ -136,7 +136,6 @@ public class DatabaseBackend extends SQLiteOpenHelper { + SQLiteAxolotlStore.OWN + " INTEGER, " + SQLiteAxolotlStore.FINGERPRINT + " TEXT, " + SQLiteAxolotlStore.CERTIFICATE + " BLOB, " - + SQLiteAxolotlStore.TRUSTED + " TEXT, " + SQLiteAxolotlStore.TRUST + " TEXT, " + SQLiteAxolotlStore.ACTIVE + " NUMBER, " + SQLiteAxolotlStore.LAST_ACTIVATION + " NUMBER," @@ -554,7 +553,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.execSQL(CREATE_MESSAGE_TYPE_INDEX); } - if (oldVersion < 46 && newVersion >= 46) { + if (oldVersion < 46 && newVersion == 46) { // only available for old database version 46 if (!isColumnExisting(db, SQLiteAxolotlStore.IDENTITIES_TABLENAME, SQLiteAxolotlStore.TRUSTED)) { db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.TRUSTED); // TODO - just to make old databases importable, column isn't needed at all } diff --git a/src/main/java/de/pixart/messenger/services/ExportBackupService.java b/src/main/java/de/pixart/messenger/services/ExportBackupService.java index 4603a441f..0d976c484 100644 --- a/src/main/java/de/pixart/messenger/services/ExportBackupService.java +++ b/src/main/java/de/pixart/messenger/services/ExportBackupService.java @@ -162,25 +162,32 @@ public class ExportBackupService extends Service { return cursorToString(tablename, cursor, max, false); } - private static String cursorToString(String tablename, Cursor cursor, int max, boolean ignore) { + private static String cursorToString(final String tablename, final Cursor cursor, int max, boolean ignore) { + final boolean identities = SQLiteAxolotlStore.IDENTITIES_TABLENAME.equals(tablename); StringBuilder builder = new StringBuilder(); builder.append("INSERT "); if (ignore) { builder.append("OR IGNORE "); } builder.append("INTO ").append(tablename).append("("); + int skipColumn = -1; for (int i = 0; i < cursor.getColumnCount(); ++i) { + final String name = cursor.getColumnName(i); + if (identities && SQLiteAxolotlStore.TRUSTED.equals(name)) { + skipColumn = i; + continue; + } if (i != 0) { builder.append(','); } - builder.append(cursor.getColumnName(i)); + builder.append(name); } builder.append(") VALUES"); for (int i = 0; i < max; ++i) { if (i != 0) { builder.append(','); } - appendValues(cursor, builder); + appendValues(cursor, builder, skipColumn); if (i < max - 1 && !cursor.moveToNext()) { break; } @@ -190,9 +197,12 @@ public class ExportBackupService extends Service { return builder.toString(); } - private static void appendValues(Cursor cursor, StringBuilder builder) { + private static void appendValues(final Cursor cursor, final StringBuilder builder, final int skipColumn) { builder.append("("); for (int i = 0; i < cursor.getColumnCount(); ++i) { + if (i == skipColumn) { + continue; + } if (i != 0) { builder.append(','); } @@ -206,7 +216,6 @@ public class ExportBackupService extends Service { } } builder.append(")"); - } @Override |