From f7d5332ad2edc330428892717206cacbb88e2368 Mon Sep 17 00:00:00 2001 From: FC Stegerman Date: Fri, 23 Jun 2023 23:48:20 +0200 Subject: [PATCH 1/3] drop DB before importing --- app/src/main/java/protect/card_locker/DBHelper.java | 6 ++++++ .../card_locker/importexport/MultiFormatImporter.java | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/app/src/main/java/protect/card_locker/DBHelper.java b/app/src/main/java/protect/card_locker/DBHelper.java index 53ec2ea5ca..59d17d1992 100644 --- a/app/src/main/java/protect/card_locker/DBHelper.java +++ b/app/src/main/java/protect/card_locker/DBHelper.java @@ -323,6 +323,12 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } + public static void clearDatabase(final SQLiteDatabase db) { + db.execSQL("DELETE FROM " + LoyaltyCardDbGroups.TABLE); + db.execSQL("DELETE FROM " + LoyaltyCardDbIds.TABLE); + db.execSQL("DELETE FROM " + LoyaltyCardDbIdsGroups.TABLE); + } + private static ContentValues generateFTSContentValues(final int id, final String store, final String note) { // FTS on Android is severely limited and can only search for word starting with a certain string // So for each word, we grab every single substring diff --git a/app/src/main/java/protect/card_locker/importexport/MultiFormatImporter.java b/app/src/main/java/protect/card_locker/importexport/MultiFormatImporter.java index a5306dd336..2914756e64 100644 --- a/app/src/main/java/protect/card_locker/importexport/MultiFormatImporter.java +++ b/app/src/main/java/protect/card_locker/importexport/MultiFormatImporter.java @@ -8,6 +8,8 @@ import java.io.InputStream; +import protect.card_locker.DBHelper; + public class MultiFormatImporter { private static final String TAG = "Catima"; @@ -17,6 +19,8 @@ public class MultiFormatImporter { *

* The input stream is not closed, and doing so is the * responsibility of the caller. + *

+ * NB: this deletes all existing data! * * @return ImportExportResult.Success if the database was successfully imported, * or another result otherwise. If no Success, no data was written to @@ -43,6 +47,7 @@ public static ImportExportResult importData(Context context, SQLiteDatabase data String error = null; if (importer != null) { database.beginTransaction(); + DBHelper.clearDatabase(database); try { importer.importData(context, database, input, password); database.setTransactionSuccessful(); From 04f55afb788250af7a54209c22cb5126ac65983d Mon Sep 17 00:00:00 2001 From: FC Stegerman Date: Sat, 24 Jun 2023 00:00:22 +0200 Subject: [PATCH 2/3] warn about deleting data on import --- .../main/res/layout/import_export_activity.xml | 16 ++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 2 files changed, 17 insertions(+) diff --git a/app/src/main/res/layout/import_export_activity.xml b/app/src/main/res/layout/import_export_activity.xml index 384764242b..84fcc57a92 100644 --- a/app/src/main/res/layout/import_export_activity.xml +++ b/app/src/main/res/layout/import_export_activity.xml @@ -89,6 +89,14 @@ android:textSize="@dimen/text_size_medium" android:text="@string/importOptionFilesystemExplanation"/> + +