mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-20 04:58:27 +00:00
Fixed issue with backup and restore when creating new tables.
Fixes #7863
This commit is contained in:
parent
6bc7f2a5a4
commit
b7282589de
@ -5,6 +5,7 @@ import android.annotation.SuppressLint;
|
|||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
@ -62,6 +63,8 @@ public class FullBackupImporter extends FullBackupBase {
|
|||||||
try {
|
try {
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
|
|
||||||
|
dropAllTables(db);
|
||||||
|
|
||||||
BackupFrame frame;
|
BackupFrame frame;
|
||||||
|
|
||||||
while (!(frame = inputStream.readFrame()).getEnd()) {
|
while (!(frame = inputStream.readFrame()).getEnd()) {
|
||||||
@ -131,6 +134,19 @@ public class FullBackupImporter extends FullBackupBase {
|
|||||||
preferences.edit().putString(preference.getKey(), preference.getValue()).commit();
|
preferences.edit().putString(preference.getKey(), preference.getValue()).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void dropAllTables(@NonNull SQLiteDatabase db) {
|
||||||
|
try (Cursor cursor = db.rawQuery("SELECT name, type FROM sqlite_master", null)) {
|
||||||
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
|
String name = cursor.getString(0);
|
||||||
|
String type = cursor.getString(1);
|
||||||
|
|
||||||
|
if ("table".equals(type)) {
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS " + name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class BackupRecordInputStream extends BackupStream {
|
private static class BackupRecordInputStream extends BackupStream {
|
||||||
|
|
||||||
private final InputStream in;
|
private final InputStream in;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user