Alter table trackpoints: added elevation gain to the trackpoints table.

This commit is contained in:
Román
2020-09-03 14:55:12 +02:00
committed by Dennis Guse
parent 4b7de188fd
commit 577b9b4635
3 changed files with 37 additions and 2 deletions
@@ -25,7 +25,7 @@ public class CustomSQLiteOpenHelper extends SQLiteOpenHelper {
private static final String TAG = CustomSQLiteOpenHelper.class.getSimpleName();
private static final int DATABASE_VERSION = 26;
private static final int DATABASE_VERSION = 27;
@VisibleForTesting
public static final String DATABASE_NAME = "database.db";
@@ -70,6 +70,10 @@ public class CustomSQLiteOpenHelper extends SQLiteOpenHelper {
case 26:
upgradeFrom25to26(db);
break;
case 27:
upgradeFrom26to27(db);
break;
default:
throw new RuntimeException("Not implemented: upgrade to " + toVersion);
@@ -91,6 +95,9 @@ public class CustomSQLiteOpenHelper extends SQLiteOpenHelper {
case 25:
downgradeFrom26to25(db);
break;
case 26:
downgradeFrom27to26(db);
break;
default:
throw new RuntimeException("Not implemented: downgrade to " + toVersion);
@@ -190,4 +197,25 @@ public class CustomSQLiteOpenHelper extends SQLiteOpenHelper {
db.setTransactionSuccessful();
db.endTransaction();
}
private void upgradeFrom26to27(SQLiteDatabase db) {
db.beginTransaction();
db.execSQL("ALTER TABLE trackpoints ADD COLUMN elevation_gain FLOAT");
db.setTransactionSuccessful();
db.endTransaction();
}
private void downgradeFrom27to26(SQLiteDatabase db) {
db.beginTransaction();
db.execSQL("ALTER TABLE trackpoints RENAME TO trackpoints_old");
db.execSQL("CREATE TABLE trackpoints (_id INTEGER PRIMARY KEY AUTOINCREMENT, trackid INTEGER, longitude INTEGER, latitude INTEGER, time INTEGER, elevation FLOAT, accuracy FLOAT, speed FLOAT, bearing FLOAT, sensor_heartrate FLOAT, sensor_cadence FLOAT, sensor_power FLOAT)");
db.execSQL("INSERT INTO trackpoints SELECT _id, trackid, longitude, latitude, time, elevation, accuracy, speed, bearing, sensor_heartrate, sensor_cadence, sensor_power FROM trackpoints_old");
db.execSQL("DROP TABLE trackpoints_old");
db.setTransactionSuccessful();
db.endTransaction();
}
}