Commit 15e29eec authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Only backup the old entries if the respective tables exist

parent dd685b04
......@@ -73,9 +73,10 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
@Override
public void onBeforeUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if(oldVersion <= 1){
CursorWithDefaults cursor = CursorWithDefaults.of(db.rawQuery("SELECT Name, dns1, dns2, dns1v6, dns2v6 FROM Shortcuts", null));
List<Shortcut> shortcuts = new ArrayList<>();
List<DNSEntry> entries = new ArrayList<>();
if(tableExists("Shortcuts")){
CursorWithDefaults cursor = CursorWithDefaults.of(db.rawQuery("SELECT Name, dns1, dns2, dns1v6, dns2v6 FROM Shortcuts", null));
if(cursor.moveToFirst()){
int i = 0;
do{
......@@ -87,7 +88,9 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
}while(cursor.moveToNext());
}
cursor.close();
cursor = CursorWithDefaults.of(db.rawQuery("SELECT Name, dns1, dns2, dns1v6, dns2v6, description, CustomEntry FROM DNSEntries", null));
}
if(tableExists("DNSEntries")){
CursorWithDefaults cursor = CursorWithDefaults.of(db.rawQuery("SELECT Name, dns1, dns2, dns1v6, dns2v6, description, CustomEntry FROM DNSEntries", null));
if(cursor.moveToFirst()){
int i = 0;
do{
......@@ -103,13 +106,12 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
}while(cursor.moveToNext());
}
cursor.close();
}
db.execSQL("DROP TABLE IF EXISTS Shortcuts");
db.execSQL("DROP TABLE IF EXISTS DNSEntries");
onCreate(db);
for(DNSEntry entry: entries)insert(entry);
for(Shortcut shortcut: shortcuts){
createShortcut(shortcut);
}
for(DNSEntry entry: entries) insert(entry);
for(Shortcut shortcut: shortcuts) createShortcut(shortcut);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment