1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 03:16:51 +01:00

avoid WITHOUT ROWID when not running at least lollipop #62

This commit is contained in:
cpfeiffer 2015-06-06 00:10:38 +02:00
parent 1e89b12b15
commit 2f0d00d645
2 changed files with 21 additions and 2 deletions

View File

@ -3,6 +3,8 @@ package nodomain.freeyourgadget.gadgetbridge;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Build.VERSION;
import android.preference.PreferenceManager;
import org.slf4j.Logger;
@ -67,4 +69,8 @@ public class GBApplication extends Application {
public static ActivityDatabaseHandler getActivityDatabaseHandler() {
return mActivityDatabaseHandler;
}
public static boolean isRunningLollipopOrLater() {
return VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
}
}

View File

@ -9,6 +9,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
import nodomain.freeyourgadget.gadgetbridge.GBActivitySample;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
public class ActivityDatabaseHandler extends SQLiteOpenHelper {
@ -36,10 +37,22 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
+ KEY_INTENSITY + " SMALLINT,"
+ KEY_STEPS + " TINYINT,"
+ KEY_TYPE + " TINYINT,"
+ " PRIMARY_KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE) WITHOUT ROWID;";
+ " PRIMARY_KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE)" + getWithoutRowId();
db.execSQL(CREATE_GBACTIVITYSAMPLES_TABLE);
}
/**
* WITHOUT ROWID is only available with sqlite 3.8.2, which is available
* with Lollipop and later.
* @return the "WITHOUT ROWID" string or an empty string for pre-Lollipop devices
*/
private String getWithoutRowId() {
if (GBApplication.isRunningLollipopOrLater()) {
return " WITHOUT ROWID;";
}
return "";
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (newVersion == 5 && (oldVersion == 4 || oldVersion ==3)) {
@ -49,7 +62,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
+ KEY_INTENSITY + " SMALLINT,"
+ KEY_STEPS + " TINYINT,"
+ KEY_TYPE + " TINYINT,"
+ " PRIMARY KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE) WITHOUT ROWID;";
+ " PRIMARY KEY (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + ") ON CONFLICT REPLACE)" + getWithoutRowId();
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+";");