Make sure to always close the database
This commit is contained in:
parent
7ad38c5e1a
commit
2f1908e480
|
@ -51,8 +51,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
|
|||
|
||||
|
||||
public void addGBActivitySample(GBActivitySample GBActivitySample) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
|
||||
try (SQLiteDatabase db = this.getWritableDatabase()) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(KEY_TIMESTAMP, GBActivitySample.getTimestamp());
|
||||
values.put(KEY_PROVIDER, GBActivitySample.getProvider());
|
||||
|
@ -61,12 +60,11 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
|
|||
values.put(KEY_TYPE, GBActivitySample.getType());
|
||||
|
||||
db.insert(TABLE_GBACTIVITYSAMPLES, null, values);
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void addGBActivitySample(int timestamp, byte provider, short intensity, byte steps, byte type) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
|
||||
try (SQLiteDatabase db = this.getWritableDatabase()) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(KEY_TIMESTAMP, timestamp);
|
||||
values.put(KEY_PROVIDER, provider);
|
||||
|
@ -75,18 +73,18 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
|
|||
values.put(KEY_TYPE, type);
|
||||
|
||||
db.insert(TABLE_GBACTIVITYSAMPLES, null, values);
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
+ " where (provider=" + provider + " and timestamp>=" + timestamp_from + " and timestamp<=" + timestamp_to + ") order by timestamp";
|
||||
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
try (SQLiteDatabase db = this.getWritableDatabase()) {
|
||||
Cursor cursor = db.rawQuery(selectQuery, null);
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
|
@ -100,6 +98,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper {
|
|||
GBActivitySampleList.add(GBActivitySample);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
}
|
||||
|
||||
return GBActivitySampleList;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue