Commit c056187e authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Added default values when migrating to the new ORM scheme

parent d69a444f
......@@ -12,10 +12,12 @@ import com.frostnerd.dnschanger.database.entities.DNSRule;
import com.frostnerd.dnschanger.database.entities.DNSRuleImport;
import com.frostnerd.dnschanger.database.entities.IPPortPair;
import com.frostnerd.dnschanger.database.entities.Shortcut;
import com.frostnerd.utils.database.CursorWithDefaults;
import com.frostnerd.utils.database.MockedContext;
import com.frostnerd.utils.database.orm.Entity;
import com.frostnerd.utils.database.orm.parser.ParsedEntity;
import com.frostnerd.utils.database.orm.statementoptions.queryoptions.WhereCondition;
import com.frostnerd.utils.general.Utils;
import java.util.ArrayList;
import java.util.HashSet;
......@@ -71,30 +73,33 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
@Override
public void onBeforeUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if(oldVersion <= 1){
Cursor cursor = db.rawQuery("SELECT Name, dns1, dns2, dns1v6, dns2v6 FROM Shortcuts", null);
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(cursor.moveToFirst()){
int i = 0;
do{
shortcuts.add(new Shortcut(cursor.getString(0),
IPPortPair.wrap(cursor.getString(1), 53),
IPPortPair.wrap(cursor.getString(2), 53),
IPPortPair.wrap(cursor.getString(3), 53),
shortcuts.add(new Shortcut(cursor.getString(0, "Name " + i++),
IPPortPair.wrap(cursor.getString(1, ""), 53),
IPPortPair.wrap(cursor.getString(2 ), 53),
IPPortPair.wrap(cursor.getString(3, ""), 53),
IPPortPair.wrap(cursor.getString(4), 53)));
}while(cursor.moveToNext());
}
cursor.close();
cursor = db.rawQuery("SELECT Name, dns1, dns2, dns1v6, dns2v6, description, CustomEntry FROM DNSEntries", null);
cursor = CursorWithDefaults.of(db.rawQuery("SELECT Name, dns1, dns2, dns1v6, dns2v6, description, CustomEntry FROM DNSEntries", null));
if(cursor.moveToFirst()){
int i = 0;
do{
DNSEntry found = DNSEntry.findDefaultEntryByLongName(cursor.getString(0));
if(found == null)entries.add(new DNSEntry(cursor.getString(0), cursor.getString(0),
IPPortPair.wrap(cursor.getString(1), 53),
if(found == null)entries.add(new DNSEntry(cursor.getString(0, "Name " + i++),
cursor.getString(0, "Name " + i),
IPPortPair.wrap(cursor.getString(1, ""), 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),
cursor.getString(5),
cursor.getInt(6) == 1));
cursor.getString(5, ""),
cursor.getInt(6, 0) == 1));
}while(cursor.moveToNext());
}
cursor.close();
......
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