diff --git a/app/src/main/java/com/adam/aslfms/SettingsActivity.java b/app/src/main/java/com/adam/aslfms/SettingsActivity.java index cac6dc7d..eac06d3f 100644 --- a/app/src/main/java/com/adam/aslfms/SettingsActivity.java +++ b/app/src/main/java/com/adam/aslfms/SettingsActivity.java @@ -131,7 +131,7 @@ protected void onCreate(Bundle savedInstanceState) { if (settings.getWhatsNewViewedVersion() < v) { new WhatsNewDialog(this).show(); settings.setWhatsNewViewedVersion(v); - mDb.alterDataBaseOnce(); // version 1.5.8 only! + mDb.alterDataBaseOnce(); // TODO: VERSION 1.5.8 only! } // Start listening service if applicable diff --git a/app/src/main/java/com/adam/aslfms/util/ScrobblesDatabase.java b/app/src/main/java/com/adam/aslfms/util/ScrobblesDatabase.java index 59f631fd..1e3ecb37 100644 --- a/app/src/main/java/com/adam/aslfms/util/ScrobblesDatabase.java +++ b/app/src/main/java/com/adam/aslfms/util/ScrobblesDatabase.java @@ -508,14 +508,22 @@ public CorrectionRule fetchCorrectioneRule(int id) { public void alterDataBaseOnce(){ try { - mDb.execSQL("ALTER TABLE " + TABLENAME_SCROBBLES + " ADD COLUMN albumartist text"); + try { + mDb.execSQL("SELECT trackartist FROM " + TABLENAME_SCROBBLES); // check if table column exists + } catch (Exception e){ + mDb.execSQL("ALTER TABLE " + TABLENAME_SCROBBLES + " ADD COLUMN trackartist text DEFAULT '' not null"); // if column not exists create column + } } catch (Exception ignore) { - // may capture already exists albumartist + // may capture already exists trackartist } try { - mDb.execSQL("ALTER TABLE " + TABLENAME_SCROBBLES + " ADD COLUMN trackartist text"); + try { + mDb.execSQL("SELECT albumartist FROM " + TABLENAME_SCROBBLES); // check if table column exists + } catch (Exception e){ + mDb.execSQL("ALTER TABLE " + TABLENAME_SCROBBLES + " ADD COLUMN albumartist text DEFAULT '' not null"); // if column not exists create column + } } catch (Exception ignore) { - // may capture already exists trackartist + // may capture already exists albumartist } } }