mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 10:35:50 +01:00
Merge branch 'db_refactoring_proposal'
This commit is contained in:
commit
dea4ee82a1
@ -31,6 +31,10 @@ public class GBApplication extends Application {
|
|||||||
// print logback's internal status
|
// print logback's internal status
|
||||||
// StatusPrinter.print(lc);
|
// StatusPrinter.print(lc);
|
||||||
// Logger logger = LoggerFactory.getLogger(GBApplication.class);
|
// Logger logger = LoggerFactory.getLogger(GBApplication.class);
|
||||||
|
|
||||||
|
// for testing DB stuff
|
||||||
|
// SQLiteDatabase db = mActivityDatabaseHandler.getWritableDatabase();
|
||||||
|
// db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFileLoggingEnabled() {
|
public static boolean isFileLoggingEnabled() {
|
||||||
|
@ -12,13 +12,12 @@ import nodomain.freeyourgadget.gadgetbridge.GBActivitySample;
|
|||||||
|
|
||||||
public class ActivityDatabaseHandler extends SQLiteOpenHelper {
|
public class ActivityDatabaseHandler extends SQLiteOpenHelper {
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 3;
|
private static final int DATABASE_VERSION = 5;
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "ActivityDatabase";
|
private static final String DATABASE_NAME = "ActivityDatabase";
|
||||||
|
|
||||||
private static final String TABLE_GBACTIVITYSAMPLES = "GBActivitySamples";
|
private static final String TABLE_GBACTIVITYSAMPLES = "GBActivitySamples";
|
||||||
|
|
||||||
private static final String KEY_ID = "id";
|
|
||||||
private static final String KEY_TIMESTAMP = "timestamp";
|
private static final String KEY_TIMESTAMP = "timestamp";
|
||||||
private static final String KEY_PROVIDER = "provider";
|
private static final String KEY_PROVIDER = "provider";
|
||||||
private static final String KEY_INTENSITY = "intensity";
|
private static final String KEY_INTENSITY = "intensity";
|
||||||
@ -32,22 +31,35 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(SQLiteDatabase db) {
|
public void onCreate(SQLiteDatabase db) {
|
||||||
String CREATE_GBACTIVITYSAMPLES_TABLE = "CREATE TABLE " + TABLE_GBACTIVITYSAMPLES + " ("
|
String CREATE_GBACTIVITYSAMPLES_TABLE = "CREATE TABLE " + TABLE_GBACTIVITYSAMPLES + " ("
|
||||||
+ KEY_ID + " INTEGER PRIMARY KEY,"
|
|
||||||
+ KEY_TIMESTAMP + " INT,"
|
+ KEY_TIMESTAMP + " INT,"
|
||||||
+ KEY_PROVIDER + " TINYINT,"
|
+ KEY_PROVIDER + " TINYINT,"
|
||||||
+ KEY_INTENSITY + " SMALLINT,"
|
+ KEY_INTENSITY + " SMALLINT,"
|
||||||
+ KEY_STEPS + " TINYINT,"
|
+ KEY_STEPS + " TINYINT,"
|
||||||
+ KEY_TYPE + " TINYINT,"
|
+ KEY_TYPE + " TINYINT,"
|
||||||
+ " UNIQUE (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE)";
|
+ " PRIMARY_KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE) WITHOUT ROWID;";
|
||||||
db.execSQL(CREATE_GBACTIVITYSAMPLES_TABLE);
|
db.execSQL(CREATE_GBACTIVITYSAMPLES_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
if (newVersion == 5 && (oldVersion == 4 || oldVersion ==3)) {
|
||||||
|
String CREATE_NEW_GBACTIVITYSAMPLES_TABLE = "CREATE TABLE NEW ("
|
||||||
|
+ KEY_TIMESTAMP + " INT,"
|
||||||
|
+ KEY_PROVIDER + " TINYINT,"
|
||||||
|
+ KEY_INTENSITY + " SMALLINT,"
|
||||||
|
+ KEY_STEPS + " TINYINT,"
|
||||||
|
+ KEY_TYPE + " TINYINT,"
|
||||||
|
+ " PRIMARY KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE) WITHOUT ROWID;";
|
||||||
|
db.execSQL(CREATE_NEW_GBACTIVITYSAMPLES_TABLE);
|
||||||
|
db.execSQL("insert into NEW select timestamp,provider,intensity,steps,type from "+ TABLE_GBACTIVITYSAMPLES+";");
|
||||||
|
db.execSQL("Drop table "+TABLE_GBACTIVITYSAMPLES+";");
|
||||||
|
db.execSQL("alter table NEW RENAME TO " + TABLE_GBACTIVITYSAMPLES + ";");
|
||||||
|
} else {
|
||||||
//FIXME: do not just recreate
|
//FIXME: do not just recreate
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_GBACTIVITYSAMPLES);
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_GBACTIVITYSAMPLES);
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addGBActivitySample(GBActivitySample GBActivitySample) {
|
public void addGBActivitySample(GBActivitySample GBActivitySample) {
|
||||||
|
Loading…
Reference in New Issue
Block a user