From 40750a3b99d2802b6dc7ca36f08db6c76e6fdfde Mon Sep 17 00:00:00 2001 From: OliE Date: Sun, 12 Nov 2017 22:37:33 +0100 Subject: [PATCH] catch sql exception on getScaleDataList method --- .../core/database/ScaleDatabase.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/database/ScaleDatabase.java b/android_app/app/src/main/java/com/health/openscale/core/database/ScaleDatabase.java index 60aab237..a5777d00 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/database/ScaleDatabase.java +++ b/android_app/app/src/main/java/com/health/openscale/core/database/ScaleDatabase.java @@ -370,27 +370,31 @@ public class ScaleDatabase extends SQLiteOpenHelper { public ArrayList getScaleDataList(int userId) { ArrayList scaleDataList = new ArrayList(); - String sortOrder = COLUMN_NAME_DATE_TIME + " DESC"; + try { + String sortOrder = COLUMN_NAME_DATE_TIME + " DESC"; - Cursor cursorScaleDB = dbRead.query( - TABLE_NAME, // The table to query - projection, // The columns to return - COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_ENABLE + "=1", // The columns for the WHERE clause - new String[]{Integer.toString(userId)}, // The values for the WHERE clause - null, // don't group the rows - null, // don't filter by row groups - sortOrder // The sort order - ); + Cursor cursorScaleDB = dbRead.query( + TABLE_NAME, // The table to query + projection, // The columns to return + COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_ENABLE + "=1", // The columns for the WHERE clause + new String[]{Integer.toString(userId)}, // The values for the WHERE clause + null, // don't group the rows + null, // don't filter by row groups + sortOrder // The sort order + ); - cursorScaleDB.moveToFirst(); - - while (!cursorScaleDB.isAfterLast()) { + cursorScaleDB.moveToFirst(); + + while (!cursorScaleDB.isAfterLast()) { scaleDataList.add(readAtCursor(cursorScaleDB)); cursorScaleDB.moveToNext(); } - cursorScaleDB.close(); + cursorScaleDB.close(); + } catch (SQLException ex) { + Log.e("ScaleDatabase", "SQL exception occured while getting scale data list: " + ex.getMessage()); + } return scaleDataList; }