1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

Add daniele's db optimization the WITHOUT ROWID

closes #62
This commit is contained in:
cpfeiffer 2015-06-05 21:46:56 +02:00
parent fc374881c5
commit c4096e6d3c
2 changed files with 9 additions and 5 deletions

View File

@ -31,6 +31,10 @@ public class GBApplication extends Application {
// print logback's internal status
// StatusPrinter.print(lc);
// Logger logger = LoggerFactory.getLogger(GBApplication.class);
// for testing DB stuff
// SQLiteDatabase db = mActivityDatabaseHandler.getWritableDatabase();
// db.close();
}
public static boolean isFileLoggingEnabled() {

View File

@ -12,7 +12,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBActivitySample;
public class ActivityDatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 4;
private static final int DATABASE_VERSION = 5;
private static final String DATABASE_NAME = "ActivityDatabase";
@ -36,20 +36,20 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
+ KEY_INTENSITY + " SMALLINT,"
+ KEY_STEPS + " TINYINT,"
+ KEY_TYPE + " TINYINT,"
+ " PRIMARY_KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE)";
+ " PRIMARY_KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE) WITHOUT ROWID;";
db.execSQL(CREATE_GBACTIVITYSAMPLES_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (newVersion == 4 && oldVersion == 3) {
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)";
+ " 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+";");
@ -92,7 +92,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
public ArrayList<GBActivitySample> getGBActivitySamples(int timestamp_from, int timestamp_to, byte provider) {
if (timestamp_to == -1) {
timestamp_to = 2147483647; // dont know what happens when I use more than max of a signed int
timestamp_to = Integer.MAX_VALUE; // dont know what happens when I use more than max of a signed int
}
ArrayList<GBActivitySample> GBActivitySampleList = new ArrayList<GBActivitySample>();
String selectQuery = "SELECT * FROM " + TABLE_GBACTIVITYSAMPLES