This commit is contained in:
Alex Sytnyk 2018-10-23 13:23:14 +03:00
parent 9c2a51fb4b
commit 9d093e36e2
7 changed files with 25 additions and 27 deletions

View file

@ -709,15 +709,16 @@ public class FavouritesDbHelper {
private SQLiteConnection openConnection(boolean readonly) {
conn = context.getSQLiteAPI().getOrCreateDatabase(FAVOURITE_DB_NAME, readonly);
if (conn.getVersion() == 0 || DATABASE_VERSION != conn.getVersion()) {
if (conn.getVersion() < DATABASE_VERSION) {
if (readonly) {
conn.close();
conn = context.getSQLiteAPI().getOrCreateDatabase(FAVOURITE_DB_NAME, false);
}
if (conn.getVersion() == 0) {
int version = conn.getVersion();
if (version == 0) {
onCreate(conn);
} else {
onUpgrade(conn, conn.getVersion(), DATABASE_VERSION);
onUpgrade(conn, version, DATABASE_VERSION);
}
conn.setVersion(DATABASE_VERSION);
}

View file

@ -170,13 +170,12 @@ public class GPXDatabase {
private SQLiteConnection openConnection(boolean readonly) {
SQLiteConnection conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly);
int version = conn.getVersion();
if (version == 0 || DB_VERSION != version) {
if (conn.getVersion() < DB_VERSION) {
if (readonly) {
conn.close();
conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, false);
}
version = conn.getVersion();
int version = conn.getVersion();
conn.setVersion(DB_VERSION);
if (version == 0) {
onCreate(conn);

View file

@ -50,18 +50,18 @@ public class DatabaseHelper {
if (conn == null) {
return null;
}
if (conn.getVersion() == 0 || DB_VERSION != conn.getVersion()) {
if (conn.getVersion() < DB_VERSION) {
if (readonly) {
conn.close();
conn = app.getSQLiteAPI().getOrCreateDatabase(DB_NAME, false);
}
if (conn.getVersion() == 0) {
conn.setVersion(DB_VERSION);
int version = conn.getVersion();
conn.setVersion(DB_VERSION);
if (version == 0) {
onCreate(conn);
} else {
onUpgrade(conn, conn.getVersion(), DB_VERSION);
onUpgrade(conn, version, DB_VERSION);
}
}
return conn;
}

View file

@ -316,15 +316,16 @@ public class SearchHistoryHelper {
private SQLiteConnection openConnection(boolean readonly) {
SQLiteConnection conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly);
if (conn.getVersion() == 0 || DB_VERSION != conn.getVersion()) {
if (conn.getVersion() < DB_VERSION) {
if (readonly) {
conn.close();
conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, false);
}
if (conn.getVersion() == 0) {
int version = conn.getVersion();
if (version == 0) {
onCreate(conn);
} else {
onUpgrade(conn, conn.getVersion(), DB_VERSION);
onUpgrade(conn, version, DB_VERSION);
}
conn.setVersion(DB_VERSION);
}

View file

@ -112,15 +112,14 @@ public class MapMarkersDbHelper {
private SQLiteConnection openConnection(boolean readonly) {
SQLiteConnection conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly);
if (conn == null) {
return conn;
return null;
}
int version = conn.getVersion();
if (version == 0 || DB_VERSION != version) {
if (conn.getVersion() < DB_VERSION) {
if (readonly) {
conn.close();
conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, false);
}
version = conn.getVersion();
int version = conn.getVersion();
conn.setVersion(DB_VERSION);
if (version == 0) {
onCreate(conn);

View file

@ -447,18 +447,18 @@ public class PoiFiltersHelper {
private SQLiteConnection openConnection(boolean readonly) {
conn = context.getSQLiteAPI().getOrCreateDatabase(DATABASE_NAME, readonly);
if (conn.getVersion() == 0 || DATABASE_VERSION != conn.getVersion()) {
if (conn.getVersion() < DATABASE_VERSION) {
if (readonly) {
conn.close();
conn = context.getSQLiteAPI().getOrCreateDatabase(DATABASE_NAME, false);
}
if (conn.getVersion() == 0) {
conn.setVersion(DATABASE_VERSION);
int version = conn.getVersion();
conn.setVersion(DATABASE_VERSION);
if (version == 0) {
onCreate(conn);
} else {
onUpgrade(conn, conn.getVersion(), DATABASE_VERSION);
onUpgrade(conn, version, DATABASE_VERSION);
}
}
return conn;
}
@ -477,7 +477,6 @@ public class PoiFiltersHelper {
conn.execSQL("ALTER TABLE " + FILTER_NAME + " ADD " + FILTER_COL_HISTORY + " int DEFAULT " + FALSE_INT);
conn.execSQL("ALTER TABLE " + FILTER_NAME + " ADD " + FILTER_COL_DELETED + " int DEFAULT " + FALSE_INT);
}
conn.setVersion(newVersion);
}
private void deleteOldFilters(SQLiteConnection conn) {

View file

@ -232,13 +232,12 @@ public class TravelLocalDataHelper {
private SQLiteConnection openConnection(boolean readonly) {
SQLiteConnection conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly);
int version = conn.getVersion();
if (version == 0 || DB_VERSION != version) {
if (conn.getVersion() < DB_VERSION) {
if (readonly) {
conn.close();
conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, false);
}
version = conn.getVersion();
int version = conn.getVersion();
conn.setVersion(DB_VERSION);
if (version == 0) {
onCreate(conn);