Fix gpxdatabase

This commit is contained in:
Alexey Kulish 2017-07-07 20:43:26 +03:00
parent 6d717508c4
commit 2e254d6a8d

View file

@ -129,17 +129,19 @@ public class GPXDatabase {
private SQLiteConnection openConnection(boolean readonly) { private SQLiteConnection openConnection(boolean readonly) {
SQLiteConnection conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly); SQLiteConnection conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly);
if (conn.getVersion() == 0 || DB_VERSION != conn.getVersion()) { int version = conn.getVersion();
if (version == 0 || DB_VERSION != version) {
if (readonly) { if (readonly) {
conn.close(); conn.close();
conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly); conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly);
} }
if (conn.getVersion() == 0) { version = conn.getVersion();
conn.setVersion(DB_VERSION);
if (version == 0) {
onCreate(conn); onCreate(conn);
} else { } else {
onUpgrade(conn, conn.getVersion(), DB_VERSION); onUpgrade(conn, version, DB_VERSION);
} }
conn.setVersion(DB_VERSION);
} }
return conn; return conn;
} }