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,43 +73,45 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper ...@@ -73,43 +73,45 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
@Override @Override
public void onBeforeUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onBeforeUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if(oldVersion <= 1){ if(oldVersion <= 1){
CursorWithDefaults cursor = CursorWithDefaults.of(db.rawQuery("SELECT Name, dns1, dns2, dns1v6, dns2v6 FROM Shortcuts", null));
List<Shortcut> shortcuts = new ArrayList<>(); List<Shortcut> shortcuts = new ArrayList<>();
List<DNSEntry> entries = new ArrayList<>(); List<DNSEntry> entries = new ArrayList<>();
if(cursor.moveToFirst()){ if(tableExists("Shortcuts")){
int i = 0; CursorWithDefaults cursor = CursorWithDefaults.of(db.rawQuery("SELECT Name, dns1, dns2, dns1v6, dns2v6 FROM Shortcuts", null));
do{ if(cursor.moveToFirst()){
shortcuts.add(new Shortcut(legacyString(0, cursor, "Name " + i++), int i = 0;
IPPortPair.wrap(cursor.getString(1, ""), 53), do{
IPPortPair.wrap(cursor.getString(2 ), 53), shortcuts.add(new Shortcut(legacyString(0, cursor, "Name " + i++),
IPPortPair.wrap(cursor.getString(3, ""), 53), IPPortPair.wrap(cursor.getString(1, ""), 53),
IPPortPair.wrap(cursor.getString(4), 53))); IPPortPair.wrap(cursor.getString(2 ), 53),
}while(cursor.moveToNext()); IPPortPair.wrap(cursor.getString(3, ""), 53),
IPPortPair.wrap(cursor.getString(4), 53)));
}while(cursor.moveToNext());
}
cursor.close();
} }
cursor.close(); if(tableExists("DNSEntries")){
cursor = CursorWithDefaults.of(db.rawQuery("SELECT Name, dns1, dns2, dns1v6, dns2v6, description, CustomEntry FROM DNSEntries", null)); CursorWithDefaults cursor = CursorWithDefaults.of(db.rawQuery("SELECT Name, dns1, dns2, dns1v6, dns2v6, description, CustomEntry FROM DNSEntries", null));
if(cursor.moveToFirst()){ if(cursor.moveToFirst()){
int i = 0; int i = 0;
do{ do{
DNSEntry found = DNSEntry.findDefaultEntryByLongName(cursor.getString(0)); DNSEntry found = DNSEntry.findDefaultEntryByLongName(cursor.getString(0));
if(found == null)entries.add(new DNSEntry(legacyString(0, cursor, "Name " + i++), if(found == null)entries.add(new DNSEntry(legacyString(0, cursor, "Name " + i++),
legacyString(0, cursor,"Name " + i), legacyString(0, cursor,"Name " + i),
IPPortPair.wrap(cursor.getString(1, ""), 53), IPPortPair.wrap(cursor.getString(1, ""), 53),
IPPortPair.wrap(cursor.getString(2), 53), IPPortPair.wrap(cursor.getString(2), 53),
IPPortPair.wrap(cursor.getString(3, ""), 53), IPPortPair.wrap(cursor.getString(3, ""), 53),
IPPortPair.wrap(cursor.getString(4), 53), IPPortPair.wrap(cursor.getString(4), 53),
cursor.getString(5, ""), cursor.getString(5, ""),
cursor.getInt(6, 0) == 1)); cursor.getInt(6, 0) == 1));
}while(cursor.moveToNext()); }while(cursor.moveToNext());
}
cursor.close();
} }
cursor.close();
db.execSQL("DROP TABLE IF EXISTS Shortcuts"); db.execSQL("DROP TABLE IF EXISTS Shortcuts");
db.execSQL("DROP TABLE IF EXISTS DNSEntries"); db.execSQL("DROP TABLE IF EXISTS DNSEntries");
onCreate(db); onCreate(db);
for(DNSEntry entry: entries)insert(entry); for(DNSEntry entry: entries) insert(entry);
for(Shortcut shortcut: shortcuts){ for(Shortcut shortcut: shortcuts) createShortcut(shortcut);
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