1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-12 19:54:29 +02:00

update only scale data only if its not a duplicate entry

This commit is contained in:
OliE
2016-12-21 10:17:44 +01:00
parent 33ed28cbbb
commit e2500b9a07
2 changed files with 6 additions and 4 deletions

View File

@@ -177,9 +177,9 @@ public class OpenScale {
Log.e("OpenScale", "Can't parse date time string while adding to the database");
}
scaleDB.insertEntry(scaleData);
updateScaleData();
if (scaleDB.insertEntry(scaleData)) {
updateScaleData();
}
}
public void updateScaleData(long id, String date_time, float weight, float fat, float water, float muscle, float waist, float hip, String comment) {

View File

@@ -113,8 +113,9 @@ public class ScaleDatabase extends SQLiteOpenHelper {
Cursor cursorScaleDB = db.query(TABLE_NAME, new String[] {COLUMN_NAME_DATE_TIME}, COLUMN_NAME_DATE_TIME + "=? AND " + COLUMN_NAME_USER_ID + "=?",
new String[] {formatDateTime.format(scaleData.date_time), Integer.toString(scaleData.user_id)}, null, null, null);
// we don't want double entries
if (cursorScaleDB.getCount() > 0) {
// we don't want double entries
cursorScaleDB.close();
return false;
} else {
ContentValues values = new ContentValues();
@@ -135,6 +136,7 @@ public class ScaleDatabase extends SQLiteOpenHelper {
catch (SQLException e)
{
Log.e("ScaleDatabase", "An error occured while inserting a new entry into the scale database: " + e.toString());
cursorScaleDB.close();
return false;
}
}