diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index a4090ef951..29977e007e 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -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); } diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index d64e773c1b..75c1f70443 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/helpers/DatabaseHelper.java b/OsmAnd/src/net/osmand/plus/helpers/DatabaseHelper.java index 170ec6aea9..bdd0753559 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/DatabaseHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/DatabaseHelper.java @@ -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; } diff --git a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java index a6511a6c02..fb708bf8fd 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java @@ -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); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 2d7ba2424a..51e3825f77 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index 7b048f546b..c23d25e2ab 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -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) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index 775a27ff49..1cb42d1b4a 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -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);